From 6922b1bf11ea95da92c8cc10471565091125c2b1 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 22 Sep 2023 20:58:57 +0100 Subject: [PATCH] Handle adding dates to talks that have the same title --- add_talk_dates.py | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/add_talk_dates.py b/add_talk_dates.py index 3fcc776..c5b88fb 100755 --- a/add_talk_dates.py +++ b/add_talk_dates.py @@ -1,5 +1,6 @@ #!/usr/bin/python3 +import collections import datetime import os @@ -37,12 +38,14 @@ def process_schedule(filename: str, short_name: str) -> None: print((conf.short_name, conf.title)) + by_title = collections.defaultdict(list) + root = lxml.etree.parse(filename).getroot() for day in root.findall(".//day"): day_index_str = day.get("index") # assert day_index_str is not None # day_index = int(day_index_str) - print("day", day_index_str) + # print("day", day_index_str) for event_element in day.findall(".//event"): title = read_field(event_element, "title") start = read_field(event_element, "start") @@ -55,19 +58,35 @@ def process_schedule(filename: str, short_name: str) -> None: dt = datetime.datetime.fromisoformat(d + " " + start) q = model.Event.query.filter_by(title=title, conference=conf) - if q.count() != 1: + if q.count() < 2: continue + by_title[title].append((dt, read_field(event_element, "abstract"))) + + continue + event = q.one() event.event_date = dt event.abstract = read_field(event_element, "abstract") print(start, title) + for title, events in by_title.items(): + q = model.Event.query.filter_by(title=title, conference=conf).order_by( + model.Event.id + ) + if q.count() != len(events): + continue + print((short_name, title)) + for event, (dt, abstract) in zip(q, events): + print(" ", event.id, dt) + event.event_date = dt + event.abstract = abstract + for f in os.scandir(schedules_loc): if f.is_dir(): continue print(f.name) process_schedule(f.path, f.name) - # database.session.commit() + database.session.commit()