Download script schedule
This commit is contained in:
		
							parent
							
								
									4fdb91a6c0
								
							
						
					
					
						commit
						594da5943a
					
				| 
						 | 
				
			
			@ -0,0 +1,44 @@
 | 
			
		|||
#!/usr/bin/env python3
 | 
			
		||||
# -*- coding: utf-8 -*-
 | 
			
		||||
import requests
 | 
			
		||||
import json
 | 
			
		||||
import os
 | 
			
		||||
 | 
			
		||||
# Schritt 1: Herunterladen der JSON-Datei
 | 
			
		||||
url = "https://talks.dhcp.cfhn.it/dhcp-2024/schedule/export/schedule.json"
 | 
			
		||||
response = requests.get(url)
 | 
			
		||||
 | 
			
		||||
# Überprüfen, ob die Anfrage erfolgreich war
 | 
			
		||||
if response.status_code == 200:
 | 
			
		||||
    schedule_data = response.json()  # JSON-Daten laden
 | 
			
		||||
 | 
			
		||||
    # Schritt 2: Ersetzen des Raum-Namens "A002 Hauptraum" durch "A002"
 | 
			
		||||
    def replace_room_names(data):
 | 
			
		||||
        # Wenn data ein Wörterbuch ist, prüfen wir die Schlüssel und Werte
 | 
			
		||||
        if isinstance(data, dict):
 | 
			
		||||
            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)
 | 
			
		||||
        # Wenn data eine Liste ist, gehen wir durch jedes Element
 | 
			
		||||
        elif isinstance(data, list):
 | 
			
		||||
            for item in data:
 | 
			
		||||
                replace_room_names(item)
 | 
			
		||||
 | 
			
		||||
    replace_room_names(schedule_data)
 | 
			
		||||
 | 
			
		||||
    # Schritt 3: Speichern der geänderten Datei
 | 
			
		||||
    output_path = "static/schedule.json"
 | 
			
		||||
    os.makedirs(os.path.dirname(output_path), exist_ok=True)
 | 
			
		||||
    with open(output_path, "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.")
 | 
			
		||||
else:
 | 
			
		||||
    print("Fehler beim Herunterladen der Datei:", response.status_code)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue