/
ical-generator.py
68 lines (60 loc) · 1.84 KB
/
ical-generator.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python
# vim: set fileencoding=utf-8
# see <http://icalendar.readthedocs.org/en/latest/usage.html>
from icalendar import Calendar, Event
from icalendar.prop import vText
from datetime import datetime
import sys
year = 2016
month = 2
daynum = {'PAZARTESİ':8, 'SALI':9, 'ÇARŞAMBA':10, 'PERŞEMBE':11, 'CUMA':12}
title = None
prof = []
cal = Calendar()
cal.add('version', '2.0')
cal.add('prodid', '-//calendar generator//mbg.istanbul.edu.tr//')
# TODO:
# - parse input
# - choose good summary
# - add description
# - add alarm
# ? add sequence
# - add UID (md5?)
chosen_sem = sys.argv[1]
for fname in sys.argv[2:]:
for line in file(fname,'r'):
if len(line)>3:
cmd, arg = line.strip().split(None, 1)
# print cmd
if cmd == 'D':
day = arg
elif cmd == 'S':
sem = arg
elif cmd == 'H':
start, end = arg.split('-')
shour,smin = start.split('.')
ehour,emin = end.split('.')
elif cmd == 'T':
title = arg
elif cmd == 'L':
location = arg
elif cmd == 'P':
prof.append(arg)
else:
if title is not None and sem.startswith(chosen_sem):
event = Event()
event.add('summary', vText(title))
description = vText(" ".join(prof))
#event['description'] = description
event.add('description', vText(description))
event.add('dtstart', datetime(year, month, daynum[day],
int(shour), int(smin), 0))
event.add('dtend', datetime(year, month, daynum[day],
int(ehour), int(emin), 0))
event.add('dtstamp', datetime.now())
event.add('location', vText(location))
event.add('rrule', {"FREQ":"WEEKLY", "INTERVAL":"1", "COUNT":"14"})
cal.add_component(event)
title = None
prof = []
print cal.to_ical()