64 lines
2.0 KiB
Python
Executable File
64 lines
2.0 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
"""
|
|
Script to Download Schedule
|
|
and rename rooms
|
|
"""
|
|
|
|
from pathlib import Path
|
|
import json
|
|
import requests
|
|
|
|
URL = "https://talks.dhcp.cfhn.it/dhcp-2024/schedule/export/schedule.json"
|
|
response = requests.get(URL, timeout=23)
|
|
|
|
if response.status_code == 200:
|
|
schedule_data = response.json() # JSON-Daten laden
|
|
|
|
# pylint: disable=too-many-branches
|
|
def replace_room_names(data):
|
|
"""
|
|
Funktion zum Umbenennen der Namen
|
|
"""
|
|
if isinstance(data, dict):
|
|
# edit room value
|
|
keys_to_replace = {}
|
|
for key, value in data.items():
|
|
if value == "D002 Vortragsraum":
|
|
data[key] = "D002"
|
|
elif value == "Haupteingang":
|
|
data[key] = "Eingang"
|
|
elif value == "A017 Workshopraum":
|
|
data[key] = "A017"
|
|
else:
|
|
replace_room_names(value)
|
|
|
|
# edit room key
|
|
new_key = key
|
|
if key == "D002 Vortragsraum":
|
|
new_key = "D002"
|
|
elif key == "Haupteingang":
|
|
new_key = "Eingang"
|
|
elif key == "A017 Workshopraum":
|
|
new_key = "A017"
|
|
|
|
# and apply changes if needed
|
|
if new_key != key:
|
|
keys_to_replace[key] = new_key
|
|
for old_key, new_key in keys_to_replace.items():
|
|
data[new_key] = data.pop(old_key)
|
|
|
|
elif isinstance(data, list):
|
|
for item in data:
|
|
replace_room_names(item)
|
|
|
|
replace_room_names(schedule_data)
|
|
|
|
# save JSON
|
|
OUTPUT_PATH = Path("static/schedule.json")
|
|
OUTPUT_PATH.parent.mkdir(parents=True, exist_ok=True)
|
|
with OUTPUT_PATH.open("w", encoding="utf-8") as f:
|
|
json.dump(schedule_data, f, ensure_ascii=False, indent=4)
|
|
|
|
print("Die Datei wurde erfolgreich unter 'static/schedule.json' gespeichert.")
|