-
Notifications
You must be signed in to change notification settings - Fork 0
/
hours.py
37 lines (33 loc) · 1.09 KB
/
hours.py
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
def midnight(days_offset=0):
import time
etime=int(time.time()) - time.altzone
midnight = (etime - (etime % 86400)) + time.altzone + 86400*days_offset
return midnight
def split_by_gap(gap, times):
i = iter(times)
first = last = i.next()
for time in i:
if time > last + gap:
yield first, last
first = last = time
else:
last = time
yield first, None
def readable_time(timestamp):
from datetime import datetime
dt = datetime.fromtimestamp(timestamp)
return dt.strftime('%I:%M%p').lower()
def readable_date(timestamp):
from datetime import datetime
dt = datetime.fromtimestamp(timestamp)
return dt.strftime('%D').lower()
if __name__ == "__main__":
midnight = midnight()
import fileinput
lines = list(int(t) for t in fileinput.input() if t.strip() != '')
for begin, end in split_by_gap(1*60*60, (time for time in lines if time > midnight)):
if end is not None:
print("{0} - {1}\t{2}".format(readable_time(begin), readable_time(end), readable_date(end)))
else:
end = lines[-1]
print("{0} - ({1})\t{2}".format(readable_time(begin), readable_time(end), readable_date(end)))