-
Notifications
You must be signed in to change notification settings - Fork 0
/
gen-from-schedule-xml.py
executable file
·58 lines (43 loc) · 2.11 KB
/
gen-from-schedule-xml.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
#!/usr/bin/python3
import argparse
import subprocess
import xml.etree.ElementTree as ET
from datetime import datetime
import locale
def parse_schedule(filename):
tree = ET.parse(filename)
root = tree.getroot()
events = root.find('day').find('room').findall('event')
event_dict = { e.get('id'): e for e in events } # TODO convert to int?
return event_dict
def generate_talk_info(event_node):
id = event_node.get('id')
date_string = event_node.find('date').text
# remove colon from timezone specifier of date string
i = date_string.rindex(':')
date_string = date_string[:i] + date_string[i+1:]
date = datetime.strptime(date_string, '%Y-%m-%dT%H:%M:%S%z')
locale.setlocale(locale.LC_ALL, 'de_DE')
formatted_date = date.strftime('%d. %B %Y')
title = event_node.find('title').text
subtitle = event_node.find('subtitle')
if subtitle is not None:
subtitle = subtitle.text or ''
persons = event_node.find('persons').findall('person')
persons_string = ', '.join(p.text for p in persons)
return (id, formatted_date, persons_string, title, subtitle)
def run_generator(executable, event_node):
id, formatted_date, persons_string, title, subtitle = generate_talk_info(event_node)
subprocess.check_call([executable, formatted_date, persons_string, title, subtitle, id])
def main():
parser = argparse.ArgumentParser(description='Intro/Outro Generator XML Reader')
parser.add_argument('xmlfile', help='Schedule xml filename.')
parser.add_argument('eventids', nargs='*', help='Event IDs for the events intros should be generated for. Defaults to all events present in schedule file if omitted.')
parser.add_argument('--executable', metavar='E', default='./.internal-gen.sh', help='Name of Intro/Outro generator script. Defaults to "./.internal-gen.sh", which should work inside this repository.')
args = parser.parse_args()
event_dict = parse_schedule(args.xmlfile)
eventids = args.eventids if args.eventids else event_dict.keys()
for i in eventids:
run_generator(args.executable, event_dict[i])
if __name__ == "__main__":
main()