#!/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()