Changeset 10:d3a34cb9b65f in stamper
- Timestamp:
- Jul 8, 2014, 10:41:44 AM (10 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
bin/stamps
r3 r10 1 1 #!/usr/bin/env python 2 2 3 import sys3 import argparse 4 4 from stamper import Stamper 5 6 7 def usage(name):8 msg = """9 Usage:10 11 To gather information of recorded times: %(name)s12 13 Recorded times for a given customer: %(name)s customer14 15 Detailed times for a given customer: %(name)s customer details16 """ % {'name': name}17 print(msg)18 5 19 6 20 7 if __name__ == '__main__': 21 8 9 parser = argparse.ArgumentParser( 10 description='stamps: show recorded times information') 11 parser.add_argument('customer', action="store", nargs='?', 12 help='Show times only for this customer') 13 parser.add_argument('filter', action="store", nargs='?', 14 help='Filter the times by date range') 15 parser.add_argument('-v', '--verbose', action="store_true", 16 help='Include detailed times information') 17 18 args = parser.parse_args() 19 22 20 s = Stamper() 23 21 s.load_stamps() 24 25 if len(sys.argv) == 1: 26 totals = s.totals() 27 print('Total times for all customers:') 28 for t in totals: 29 print(' -> %(customer)s: %(total)s' % {'customer': t, 30 'total': totals[t]}) 31 elif len(sys.argv) == 2: 32 if sys.argv[1] in s.customers(): 33 print('Total time for %(customer)s: %(total)s' % { 34 'customer': sys.argv[1], 35 'total': s.total_by_customer(sys.argv[1]) 36 }) 37 38 elif len(sys.argv) == 3: 39 if sys.argv[1] in s.customers(): 40 print('Detailed time for %(customer)s' % { 41 'customer': sys.argv[1], 42 }) 43 details, totals = s.details_by_customer(sys.argv[1]) 44 for day in details: 45 print('------ %(day)s ------' % {'day': day}) 46 for line in details[day]: 47 print(line) 48 print(' Total: %(total)s' % {'total': totals[day]}) 49 50 else: 51 usage(sys.argv[0]) 52 sys.exit(1) 22 s.show_stamps(args.customer, args.filter, args.verbose)
Note:
See TracChangeset
for help on using the changeset viewer.