-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpycal.py
More file actions
40 lines (29 loc) · 1017 Bytes
/
pycal.py
File metadata and controls
40 lines (29 loc) · 1017 Bytes
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
from event_storage import *
import time
from datetime import datetime
from sys import argv
import redis
# TODO 'every X days'
def parse_appointment_date (s):
target_time = None
for pattern in ["%d", "%d %b", "%d %b %H:%M"]:
try:
target_time = datetime.strptime(s, pattern)
except ValueError:
continue
break
target_time = target_time.replace(year=datetime.today().year)
if (target_time < datetime.today()):
target_time = target_time.replace(year=datetime.today().year+1)
return target_time
r = redis.StrictRedis()
if __name__ == "__main__":
if (len(argv) == 1):
#print "Next 3 appointments:"
#map(print_appointment, get_appointments(r, 3))
map(print_appointment, get_appointments(r))
print "If no appointments, show help instead."
print "Example: pycal ..."
else:
date = parse_appointment_date(argv[1])
print_appointment(add_appointment(r, date, "test appointment"))