forked from voc/schedule
-
Notifications
You must be signed in to change notification settings - Fork 1
/
schedule_gpn.py
executable file
·213 lines (173 loc) · 7.14 KB
/
schedule_gpn.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
210
211
212
213
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
#import requests
import json
import re
import requests
import pytz
import os
import sys
import optparse
import uuid
# import git as gitlib
from voc.schedule import Schedule, ScheduleEncoder, Event
from voc.tools import commit_changes_if_something_relevant_changed, ensure_folders_exist, export_filtered_schedule, git, harmonize_event_type, load_json, write
from voc import rc3hub
tz = pytz.timezone('Europe/Amsterdam')
parser = optparse.OptionParser()
parser.add_option('--online', action="store_true", dest="online", default=False)
parser.add_option('--show-assembly-warnings', action="store_true", dest="show_assembly_warnings", default=False)
parser.add_option('--fail', action="store_true", dest="exit_when_exception_occours", default=False)
parser.add_option('--git', action="store_true", dest="git", default=False)
parser.add_option('--debug', action="store_true", dest="debug", default=False)
options, args = parser.parse_args()
local = True
use_offline_frab_schedules = False
only_workshops = False
xc3 = "GPN22"
main_schedule_url = 'https://cfp.gulas.ch/gpn22/schedule/export/schedule.json'
additional_schedule_urls = [
{
'name': 'GPN21 Lounge',
'url': 'https://cfp.gulas.ch/gpn22-lounge/schedule/export/schedule.json',
'id_offset': 1000,
'slug': 'lounge',
}
]
id_offsets = {
}
# this list/map is required to sort the events in the schedule.xml in the correct way
# other rooms/assemblies are added at the end on demand.
rooms = {
'channels': [
# channels with video recordings/livestream – same order as streaming website
],
'rooms': [
],
'music': [
]
}
output_dir = "./out/"+ xc3
secondary_output_dir = "./out/" + xc3
# expand relative out_dir paths
if not output_dir.startswith('/'):
output_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), output_dir)
if not secondary_output_dir.startswith('/'):
secondary_output_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), secondary_output_dir)
if len(sys.argv) == 2:
output_dir = sys.argv[1]
ensure_folders_exist(output_dir, secondary_output_dir)
os.chdir(output_dir)
present_slugs = []
present_ids = []
present_uuids = []
def cleanup_event(event):
event['description'] = re.sub(u'[^\u0020-\uD7FF\u0009\u000A\u000D\uE000-\uFFFD\U00010000-\U0010FFFF]+', '', event.get('description'))
# slug should replace gpn21-lounge with gpn21_lounge
event['slug'] = event.get('slug').replace('gpn21-lounge', 'gpn21_lounge')
# handle duplicate ids
while event.get('id') in present_ids:
event['id'] = event.get('id') + 5000
print("id duplicate, new id: " + str(event.get('id')))
present_ids.append(event.get('id'))
# handle duplicate slugs
if event.get('slug') in present_slugs:
event['slug'] = event.get('slug') + '_' + str(event.get('id'))
print("slug duplicate, new slug: " + event.get('slug'))
present_slugs.append(event.get('slug'))
# handle duplicate uuid, replace uuid with new uuid (hashed by date and title)
if event.get('guid') in present_uuids:
# generate new uuid, hash formated as uuid
event['guid'] = str(uuid.uuid5(uuid.NAMESPACE_DNS, str(event.get('date')) + str(event.get('title'))))
print("uuid duplicate, new uuid: " + str(event.get('guid')))
present_uuids.append(event.get('guid'))
# we never record workshops or meetups
if event["type"] in ["Workshop", "Meetup"]:
event["do_not_record"] = True
for key in event.keys():
if type(event[key]) is str:
# cleanup windows and macOS line endings
event[key] = event[key].replace("\r\n", "\n").replace("\r", "\n")
return True
def main():
full_schedule = Schedule.from_url(main_schedule_url)
print(' version: ' + full_schedule.version())
print(' contains {events_count} events, with local ids from {min_id} to {max_id}'.format(**full_schedule.stats.__dict__))
# append lounge url
for entry in additional_schedule_urls:
try:
print('\n== SUB Event ' + entry['name'])
url = entry['url'].replace('schedule.xml', 'schedule.json')
if not url:
print(' has no schedule_url yet – ignoring')
continue
other_schedule = Schedule.from_url(url)
id_offset = entry.get('id_offset') or id_offsets.get(entry['name']) or 0
other_schedule["version"] = entry['slug']+other_schedule["version"]
if full_schedule.add_events_from(other_schedule, id_offset=id_offset, options={
**(entry.get('options') or {}),
'prefix_person_ids': entry.get('prefix'),
}):
print(' success')
except KeyboardInterrupt:
exit()
except requests.exceptions.HTTPError as e:
if e.response.status_code == 404:
print(' not yet available (404)')
else:
print(' HTTP ERROR: ' + str(e))
if options.exit_when_exception_occours:
raise e
except Exception as e:
print(' UNEXPECTED ERROR:' + str(sys.exc_info()[1]))
if options.exit_when_exception_occours:
raise e
for day in full_schedule["conference"]["days"]:
for room in day["rooms"]:
for event in day["rooms"][room]:
cleanup_event(event)
#
# write all events to one big schedule.json/xml
write('\nExporting... ')
full_schedule.export('everything')
print('\nDone')
print(' version: ' + full_schedule.version())
print('\n rooms: ')
for room in full_schedule.rooms():
print(' - ' + room)
print()
# filter and export the schedule.xml for workshops
def schedule_filter(e):
status = e["id"]
if e["type"] in ["Workshop"] and e["room"] in ["HfG Raum 112", "HfG Raum 115", "ZKM Kubus"]:
status = None
return status
schedule_workshops = full_schedule.copy()
schedule_workshops_remove = schedule_workshops.foreach_event(schedule_filter)
for r in schedule_workshops_remove:
schedule_workshops.remove_event(r)
schedule_workshops.export('workshop-reservation')
# filter and export the schedule.xml for talks
def schedule_filter(e):
status = e["id"]
if e["type"] in ["Vortrag", "Vortrag (kurz)"]:
status = None
return status
schedule_talks = full_schedule.copy()
schedule_talks_remove = schedule_talks.foreach_event(schedule_filter)
for r in schedule_talks_remove:
schedule_talks.remove_event(r)
schedule_talks.export('all-talks')
# filter and export the schedule.xml for talks
def schedule_filter(e):
status = e["id"]
if e["type"] in ["Vortrag", "Vortrag (kurz)"] and e["do_not_record"] == False:
status = None
return status
schedule_talks = full_schedule.copy()
schedule_talks_remove = schedule_talks.foreach_event(schedule_filter)
for r in schedule_talks_remove:
schedule_talks.remove_event(r)
schedule_talks.export('recorded-talks')
if __name__ == '__main__':
main()