From e3ec37c0a572c40d110ec0b076318f5f64823c2b Mon Sep 17 00:00:00 2001 From: Michael Weiss Date: Thu, 20 Jun 2024 22:09:52 +0200 Subject: [PATCH] bin/convert_from_pretalx.py: Use a variable/parameter for the year The warning is useful because of all the hard-coded values. --- bin/convert_from_pretalx.py | 16 +++++++++++++--- bin/update-schedule.py | 2 +- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/bin/convert_from_pretalx.py b/bin/convert_from_pretalx.py index 0f2835e..ddb31db 100755 --- a/bin/convert_from_pretalx.py +++ b/bin/convert_from_pretalx.py @@ -1,18 +1,28 @@ #!/usr/bin/env python3 +""" +Usage: ./convert_from_pretalx.py [YEAR] +Creates: "talks.json" based on the JSON data from our Pretalx CfP server. +""" + import json +import sys from datetime import datetime, timedelta import urllib.request -schedule_url = "https://cfp.tuebix.org/tuebix-2024/schedule/export/schedule.json" +YEAR = int(sys.argv[1] if len(sys.argv) == 2 else datetime.now().year) +if YEAR != 2024: + print("Warning: Potentially unsupported year.") + +schedule_url = f"https://cfp.tuebix.org/tuebix-{YEAR}/schedule/export/schedule.json" with urllib.request.urlopen(schedule_url) as data: schedule = json.load(data) with open("schedule.json", "w") as file: json.dump(schedule, file) # TODO: Don't hardcode the year, answer IDs, etc. -answers_url = "https://cfp.tuebix.org/api/events/tuebix-2024/answers/?format=json&limit=100" +answers_url = f"https://cfp.tuebix.org/api/events/tuebix-{YEAR}/answers/?format=json&limit=100" with urllib.request.urlopen(answers_url) as data: all_answers = json.load(data)["results"] @@ -63,7 +73,7 @@ def gen_talks(): names, bios = merge_persons(talk['persons']) - slug = talk['slug'].removeprefix("tuebix-2024-") + slug = talk['slug'].removeprefix(f"tuebix-{YEAR}-") # TODO: Try to improve the URL IDs for 2025 (maybe just ID + URL # parameters for talk and author names (as they could change)? diff --git a/bin/update-schedule.py b/bin/update-schedule.py index 5874b8d..9ce5155 100755 --- a/bin/update-schedule.py +++ b/bin/update-schedule.py @@ -33,7 +33,7 @@ def select_year(): def main(): year = select_year() # TODO: Rewrite: - os.system("../bin/convert_from_pretalx.py") + os.system(f"../bin/convert_from_pretalx.py {year}") os.system(f"../bin/json2md.py {year}") if __name__ == "__main__":