-
Notifications
You must be signed in to change notification settings - Fork 0
/
ical_gen.py
209 lines (163 loc) · 4.86 KB
/
ical_gen.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/usr/bin/python #!/usr/bin/python
import os
import os.path
import shutil
import sys
from datetime import datetime, timedelta
from pathlib import Path
import markdown2
import pytz
import yaml
from icalendar import Calendar, Event, vCalAddress, vText
from render import PageRendered, _read
# init the calendar
cal = Calendar()
cal.add('prodid', 'ical_gen')
cal.add('version', "2.0" )
SLOTS_META = {}
def define_slot(id, start, minutes, kind=None):
global SLOTS_META, LE
if isinstance(start, str):
s = datetime.fromisoformat(start)
else:
s = start
e = s + timedelta(minutes=minutes)
LE = e
SLOTS_META[id] = (s, e, kind)
LE = None
def create_break(title, start, minutes):
global LE
if isinstance(start, str):
s = datetime.fromisoformat(start)
else:
s = start
e = s + timedelta(minutes=minutes)
LE = e
# Add subcomponents
event = Event()
event.add("uid", hash(title))
event.add("dtstamp", datetime.now())
event.add('summary', title)
#event.add('description', c)
event.add('dtstart', s)
event.add('dtend', e)
# Add the organizer
organizer = vCalAddress('MAILTO:weigl@kit.edu')
# Add parameters of the event
organizer.params['name'] = vText('Alexander Weigl')
organizer.params['role'] = vText('Program Chair')
event['organizer'] = organizer
event['location'] = vText('Bad Herrenalb, Germany')
cal.add_component(event)
day0 = lambda x: f'2024-07-29T{x}:00+02:00'
day1 = lambda x: f'2024-07-30T{x}:00+02:00'
day2 = lambda x: f'2024-07-31T{x}:00+02:00'
day3 = lambda x: f'2024-08-01T{x}:00+02:00'
C_SOCIAL = 'blue'
C_BREAK = 'grey'
C_INVITED = 'red'
C_KEY = 'turkoise'
C_KEYM = 'lightblue'
define_slot(999, day0('12:35'), 60*5, C_SOCIAL)
define_slot(998, day1('19:00'), 120, C_SOCIAL)
create_break('Dinner: Klosterschänke', day2('19:00'), 180)
#
create_break('Coffee Break', day1('10:30'), 30)
create_break('Lunch', day1('12:30'), 30)
create_break('Coffee Break', day1('15:30'), 30)
#
create_break('Coffee Break', day2('10:30'), 30)
create_break('Lunch', day2('12:30'), 30)
create_break('Coffee Break', day2('15:30'), 30)
#
create_break('Coffee Break', day3('10:45'), 30)
create_break('Lunch', day3('12:30'), 30)
define_slot(10, day1('08:45'), 15)
define_slot(11, LE, 60)
define_slot(12, LE, 15)
define_slot(123, LE, 15)
define_slot(19, day1('11:00'), 30)
define_slot(191, LE, 15)
define_slot(192, LE, 15)
define_slot(193, LE, 30)
define_slot(116, day1('14:00'), 30)
define_slot(117, LE, 30)
define_slot(118, LE, 30)
define_slot(216, day1('14:00'), 30)
define_slot(217, LE, 30)
define_slot(218, LE, 30)
define_slot(113, day1('16:00'), 30)
define_slot(114, LE, 30)
define_slot(115, LE, 30)
define_slot(215, day1('16:00'), 30)
define_slot(214, LE, 30)
define_slot(213, LE, 30)
define_slot(219, LE, 15)
define_slot(220, LE, 15)
#####################################
define_slot(20, day2('09:00'), 60)
define_slot(22, LE, 30)
define_slot(33, LE, 15)
define_slot(13, day2('11:00'), 30)
define_slot(14, LE, 30)
define_slot(15, LE, 30)
define_slot(207, day2('14:00'), 30)
define_slot(208, LE, 30)
define_slot(209, LE, 30)
define_slot(16, day2('16:00'), 25)
define_slot(17, LE, 25)
define_slot(18, LE, 25)
define_slot(199, LE, 15)
define_slot(1999, LE, 30)
#####################################
define_slot(30, day3('09:00'), 60)
define_slot(31, LE, 15)
define_slot(301, LE, 15)
define_slot(34, LE, 15)
#define_slot(22, LE, 15)
define_slot(32, day3('11:10'), 15)
define_slot(21, LE, 15)
define_slot(35, LE, 15)
define_slot(36, day3('12:20'), 10)
#from pprint import pprint
#pprint(SLOTS_META)
def main():
talks = []
bySlot = {}
for fn in Path("talks/").rglob("*.md"):
t = _read(fn)
try:
bySlot[t.meta['slot']] = t
talks.append(t)
except:
print(f"No slot defined for {fn}")
for p in talks:
# Add subcomponents
m = p.meta
c = p.content
event = Event()
author = str(m['author'])
title = m['title']
event.add('summary', f"{author}: {title}")
event.add('description', c)
try:
(s,e,k) = SLOTS_META[m['slot']]
event.add('color', k)
event.add('categories', k)
event.add('dtstart', s)
event.add('dtend', e)
except:
print(f"Slot not defined {m['slot']}")
# Add the organizer
organizer = vCalAddress('MAILTO:weigl@kit.edu')
# Add parameters of the event
organizer.params['name'] = vText('Alexander Weigl')
organizer.params['role'] = vText('Program Chair')
event['organizer'] = organizer
event['location'] = vText('Bad Herrenalb, Germany')
cal.add_component(event)
# Write to disk
output = Path("public") / 'events.ics'
with output.open('wb') as f:
f.write(cal.to_ical())
if __name__ == "__main__": main()