From 756177089df4c0138f23d23b48839e5499171508 Mon Sep 17 00:00:00 2001 From: Luca Date: Mon, 12 Sep 2022 00:32:58 +0200 Subject: [PATCH] Fix duration parsing --- bin/fetch_schedule.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/bin/fetch_schedule.py b/bin/fetch_schedule.py index 012c979..c4feed4 100755 --- a/bin/fetch_schedule.py +++ b/bin/fetch_schedule.py @@ -11,11 +11,21 @@ ROOM_SEQUENCE = ('Sondermaschinenbau', 'Smart City Schmiede', 'Sofaecke', 'Auße SCHEDULE_URL = 'https://cfp.fairydust.reisen/iger-2022/schedule/export/schedule.json' TIMEZONE = 'Europe/Berlin' -def parse_duration(s, num_parts): +def parse_duration(s): duration = 0 - for t in s.split(':', maxsplit=num_parts-1): + components = s.split(':') + + if len(components) == 3: + duration += int(components[0]) + duration *= 24 + components = components[1:] + + if len(components) == 2: + duration += int(components[0]) duration *= 60 - duration += int(t) + duration += int(components[1]) + else: + raise RuntimeError(f'invalid duration format: {s}') return duration @@ -54,14 +64,14 @@ def main(): event['start_date'] = date - date += timedelta(seconds=parse_duration(event['duration'], 2)*60) + date += timedelta(seconds=parse_duration(event['duration'])*60) if end_date is None or date > end_date: end_date = date event['end_date'] = date timeline = [] - timeslot = parse_duration(conference['timeslot_duration'], 2) + timeslot = parse_duration(conference['timeslot_duration']) for offset in range(0, int((end_date-start_date).total_seconds()), GRANULARITY*60): date = start_date + timedelta(seconds=offset) timeline.append({'date': date.strftime('%Y-%m-%d'), 'start': offset//(timeslot*60)+1, 'time': date.strftime('%H:%M')})