Fix duration parsing
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Luca 2022-09-12 00:32:58 +02:00
parent be97c32d03
commit 756177089d
1 changed files with 15 additions and 5 deletions

View File

@ -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')})