From 6b07f3d3ecd7eeee7e7ae509aaaa7eb1466aecef Mon Sep 17 00:00:00 2001 From: Luca Date: Wed, 6 Jan 2021 16:47:27 +0100 Subject: [PATCH] Add python script for generating talks.txt --- fetch.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 fetch.py diff --git a/fetch.py b/fetch.py new file mode 100755 index 0000000..ab1512f --- /dev/null +++ b/fetch.py @@ -0,0 +1,58 @@ +#!/usr/bin/python3 + +from argparse import ArgumentParser +from urllib.request import urlopen +from lxml import etree + +def filter_schedule(url, ids, rooms, tracks): + xml = urlopen(url).read() + schedule = etree.fromstring(xml) + + for day in schedule.iter('day'): + for room in day.iter('room'): + for event in room.iter('event'): + id = event.get('id') + if ids and id not in ids: + continue + + room_name = room.get('name') + if rooms and room_name not in rooms: + continue + + track = event.find('track').text + if tracks and track not in tracks: + continue + + title = event.find('title').text + + speaker_list = None + if event.find('persons') is not None: + speakers = [] + for speaker in event.find('persons').iter('person'): + speakers.append(speaker.text) + speaker_list = ', '.join(speakers) + + yield { + 'id': id, + 'room': room_name, + 'track': track, + 'title': title, + 'speakers': speaker_list, + } + +def main(): + parser = ArgumentParser() + parser.add_argument('url', help='schedule url') + parser.add_argument('--ids', nargs='+', help='select given ids') + parser.add_argument('--rooms', nargs='+', help='select given rooms') + parser.add_argument('--tracks', nargs='+', help='select given tracks') + args = parser.parse_args() + + ids = args.ids or None + rooms = args.rooms or None + tracks = args.tracks or None + for event in filter_schedule(args.url, ids, rooms, tracks): + print(f"{event['id']}\t{event['title']}\t{event['speakers']}") + +if __name__ == '__main__': + main()