modified: app.py
This commit is contained in:
58
app.py
58
app.py
@@ -17,34 +17,50 @@ def load_weather_data():
|
||||
|
||||
# Parsen der JSON-Daten
|
||||
data = json.loads(decompressed_data.decode('utf-8'))
|
||||
|
||||
|
||||
# Debug: Ausgabe der ersten Nachricht für Analysezwecke
|
||||
print(json.dumps(data["messages"][:1], indent=4))
|
||||
|
||||
# Extrahieren der relevanten Wetterdaten
|
||||
weather_data = []
|
||||
|
||||
# Beispielhafte Iteration über die JSON-Daten (anpassen, wenn die Struktur bekannt ist)
|
||||
# Verarbeite die Nachrichten
|
||||
for message in data["messages"]:
|
||||
# Gehe tiefer in die Struktur, je nachdem wie die Daten aufgebaut sind
|
||||
for station_data in message[1:]:
|
||||
station_info = {}
|
||||
if isinstance(station_data, list):
|
||||
for info in station_data:
|
||||
if isinstance(info, dict) and "key" in info:
|
||||
if info["key"] == "stationNumber":
|
||||
station_info["stationNumber"] = info["value"]
|
||||
elif info["key"] == "stationOrSiteName":
|
||||
station_info["stationName"] = info["value"]
|
||||
elif info["key"] == "airTemperature":
|
||||
station_info["temperature"] = round(info["value"] - 273.15, 2) # Umwandlung von K in °C
|
||||
elif info["key"] == "windSpeed":
|
||||
station_info["windSpeed"] = info["value"]
|
||||
elif info["key"] == "pressureReducedToMeanSeaLevel":
|
||||
station_info["pressure"] = info["value"]
|
||||
|
||||
if "stationNumber" in station_info:
|
||||
weather_data.append(station_info)
|
||||
# Debug: Nachricht anzeigen, um zu überprüfen, ob sie korrekt verarbeitet wird
|
||||
print(f"Processing message: {message}")
|
||||
|
||||
# Prüfen, ob message eine Liste ist
|
||||
if isinstance(message, list):
|
||||
for station_data in message[1:]: # Die eigentlichen Wetterdaten scheinen ab dem zweiten Element zu sein
|
||||
station_info = {}
|
||||
if isinstance(station_data, list):
|
||||
for info in station_data:
|
||||
# Prüfe, ob info ein Dictionary ist
|
||||
if isinstance(info, dict):
|
||||
# Debug: Anzeigen, was info ist
|
||||
print(f"Processing station info: {info}")
|
||||
if "key" in info:
|
||||
if info["key"] == "stationNumber":
|
||||
station_info["stationNumber"] = info["value"]
|
||||
elif info["key"] == "stationOrSiteName":
|
||||
station_info["stationName"] = info["value"]
|
||||
elif info["key"] == "airTemperature":
|
||||
station_info["temperature"] = round(info["value"] - 273.15, 2) # Umwandlung von K in °C
|
||||
elif info["key"] == "windSpeed":
|
||||
station_info["windSpeed"] = info["value"]
|
||||
elif info["key"] == "pressureReducedToMeanSeaLevel":
|
||||
station_info["pressure"] = info["value"]
|
||||
|
||||
# Nur vollständige Datensätze hinzufügen
|
||||
if "stationNumber" in station_info:
|
||||
weather_data.append(station_info)
|
||||
|
||||
# Sortiere nach stationNumber
|
||||
weather_data.sort(key=lambda x: x["stationNumber"])
|
||||
|
||||
return weather_data
|
||||
|
||||
|
||||
# Flask Route für die Hauptseite
|
||||
@app.route('/')
|
||||
def index():
|
||||
|
||||
Reference in New Issue
Block a user