-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathworking_week.py
More file actions
executable file
·39 lines (35 loc) · 1.25 KB
/
working_week.py
File metadata and controls
executable file
·39 lines (35 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#!/usr/bin/env python
# $Id: working_week.py,v 1.1 2008/12/10 18:12:50 guest Exp $
#
# Call as working.py | working_week.py
import sys
import datetime
def main():
haveData = False
week = 0
monday = None
lastday = None
for line in sys.stdin:
date, hours = line.split()
year, month, day = date.split('-')
#print "xxx:", year, month, day, "->", hours
day = datetime.date(int(year), int(month), int(day))
if (day.weekday() == 0):
# we have a Monday
# do we have data for the last week?
if (haveData):
# yes, print it
# monday is the last monday we save, lastday is the last day we summed up the hours
print "From %s to %s -> %1.1f hours" % (monday, lastday, float(week) / 10)
# we have data, so start to sum up the weekly work hours
haveData = True
week = int(hours)
# save this Monday in var monday for the next print out
monday = day
elif (haveData):
# we started to sum up weekly work hours
week += int(hours)
# and remember this day in var lastday used for print out
lastday = day
if __name__ == "__main__":
main()