4 timelog_filename
= sys
.argv
[1]
5 hourly_rate
= float(sys
.argv
[2])
7 fo
= open(timelog_filename
)
9 lines
= [item
.replace("\n", '') for item
in lines
]
16 total
= datetime
.timedelta()
22 dt
= datetime
.datetime
.strptime(line
, "%a %b %d %H:%M:%S %Z %Y")
23 # after here a correctly formatted date is found
25 if in_working
: # found the end datetime
27 # calc diff and add to total
29 print "one punch for %.2f hours" % (punch
.seconds
/3600.0,)
31 else: # found the start datetime
38 if (num_dates
%2) != 0:
39 raise Exception, "Malformed file: There needs to be an even number of datetime entries in the file to generate hours worked."
41 # now we should have the total time worked. Go ahead and print it in hours.
42 hours_worked
= total
.seconds
/3600.0
43 print "%.4f hours worked" % (hours_worked
,)
44 invoice_amount
= hours_worked
* hourly_rate
45 print "At $%s an hour this makes a total of $%.2f to invoice" % (hourly_rate
, invoice_amount
)