| 
            Last change
 on this file since 0:4cc6fc51063c was             0:4cc6fc51063c, checked in by Borja Lopez <borja@…>, 11 years ago           | 
        
        
          | 
             
Initial commit, including basic structure of the project and initial features 
 
           | 
        
        
          | 
            
           | 
        
        
          | 
            File size:
            1.4 KB
           | 
        
      
      
| Line |   | 
|---|
| 1 | #!/usr/bin/env python
 | 
|---|
| 2 | 
 | 
|---|
| 3 | import sys
 | 
|---|
| 4 | from stamper import Stamper
 | 
|---|
| 5 | 
 | 
|---|
| 6 | 
 | 
|---|
| 7 | def usage(name):
 | 
|---|
| 8 |     msg = """
 | 
|---|
| 9 |     Usage:
 | 
|---|
| 10 | 
 | 
|---|
| 11 |     To gather information of recorded times: %(name)s
 | 
|---|
| 12 | 
 | 
|---|
| 13 |     Recorded times for a given customer: %(name)s customer
 | 
|---|
| 14 | 
 | 
|---|
| 15 |     Detailed times for a given customer: %(name)s customer details
 | 
|---|
| 16 |     """ % {'name': name}
 | 
|---|
| 17 |     print(msg)
 | 
|---|
| 18 | 
 | 
|---|
| 19 | 
 | 
|---|
| 20 | if __name__ == '__main__':
 | 
|---|
| 21 | 
 | 
|---|
| 22 |     s = Stamper()
 | 
|---|
| 23 |     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)
 | 
|---|
       
      
  Note:
 See   
TracBrowser
 for help on using the repository browser.