""" Creates a schedule.json from the Hackertours planning Excel. """ import math import sys from datetime import datetime, timedelta, timezone import pandas import pytz from numpy import nan import voc.tools from voc.schedule import Schedule, Event def create_schedule(sheet_file: str, schedule_file: str): # global voc.tools.VERSION voc.tools.VERSION = "0.0.1" planning_df = pandas.read_excel(sheet_file, sheet_name="Tours") description_df = pandas.read_excel(sheet_file, sheet_name="Descriptions") descriptions = {} for index, row in description_df.iterrows(): d = {} for k in description_df.keys(): d[k] = description_df[k][index] descriptions[d['Name']] = d start = datetime(year=2025, month=12, day=26, tzinfo=pytz.timezone('Europe/Berlin')) acronym = "ht" duration = 4 schedule = Schedule.from_template( title="39C3 Hackertours", acronym="39c3ht", year=2025, month=12, day=26, days_count=5, tz="Europe/Berlin") # schedule.schedule().version = '1.0' schedule["conference"]["rooms"] = [{ "name": "Hackertours", "guid": "aa56c6c6-7dbc-4f73-b189-b8ee2245b0c3", }] # Remove reporting rows for index, row in planning_df.iterrows(): name = row['Tour'] if isinstance(name, float) and math.isnan(name): planning_df.drop(index=range(index, len(planning_df)), inplace=True) break # Sort to make stable planning_df.sort_values(by=['Tag', 'Am HT-Desk', 'Tour'], inplace=True) # in the Excel, days start at 0; the event here starts on the 26th. Normally, we would convert the 1-based day to a 0-ased offset from the start day, but here, it's 0-based for index, row in planning_df.iterrows(): name = row['Tour'] if isinstance(name, float) and math.isnan(name): break if name not in descriptions: continue start_time = row['Am HT-Desk'] event_start = start + timedelta(days=row['Tag']) event_start = event_start.replace(hour=start_time.hour, minute=start_time.minute) event_duration = row['Dauer'] print(f"name={name} day={row['Tag']} start={row['Am HT-Desk']} duration={row['Dauer']}") guid = voc.tools.gen_uuid('{}-{}-{}'.format(row['Tag'], row['Am HT-Desk'], name)) start_time_hm = event_start.strftime('%H:%M') if row['Sprache'] == "de": title = descriptions[name]['Title DE'] subtitle = descriptions[name]['Subtitle DE'] abstract = descriptions[name]['Abstract DE'] else: title = descriptions[name]['Title EN'] subtitle = descriptions[name]['Subtitle EN'] abstract = descriptions[name]['Abstract EN'] schedule.add_event(Event({ 'id': index+1, 'guid': guid, # ('logo', None, 'date': event_start.isoformat(), 'start': start_time_hm, 'duration': event_duration.strftime("%H:%M"), 'room': "Hackertours", 'slug': voc.tools.normalise_string(f"{name}-{int(row['Tag'])}-{start_time_hm}".lower()), 'url': descriptions[name]['Link'], 'title': title, 'subtitle': subtitle, 'track': "Hackertours", 'type': "Tour", 'language': row['Sprache'], 'abstract': abstract, 'description': None, 'persons': [], 'links': [ { 'url': descriptions[name]['Link'], 'title': title } ] })) schedule.export(schedule_file) if __name__ == "__main__": create_schedule(sys.argv[1], sys.argv[2])