-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbeeminder.py
executable file
·44 lines (36 loc) · 1.02 KB
/
beeminder.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
38
39
40
41
42
43
44
#!/usr/bin/env python3
import sys
from datetime import datetime
def parse_date(line):
prefix = '%Y-%m!'
if len(line.split(' ', 2)) > 2:
one, two, comment = line.split(' ', 2)
time_part = one + ' ' + two
else:
comment = None
time_part = line
time_part = datetime.now().strftime(prefix) + time_part
fmt = prefix + '%d %H:%M'
try:
return datetime.strptime(time_part, fmt), comment
except ValueError:
sys.stderr.write("Failed to parse %r" % line)
raise
if sys.stdin.isatty():
sys.stderr.write('format: day hour:min [comment]\n')
data = []
while True:
try:
line = sys.stdin.readline().strip()
except EOFError:
break
if not line:
break
date, comment = parse_date(line)
hours = date.hour + date.minute / 60.0
processed_input = date.strftime('%F %R')
if comment:
processed_input += ' ' + comment
data.append((date.day, hours, processed_input))
for row in data:
print('%s %f "%s"' % row)