modified: app.py

This commit is contained in:
SimolZimol
2024-09-10 13:41:43 +02:00
parent 0c1723d0ac
commit d5ef95350d

19
app.py
View File

@@ -25,7 +25,7 @@ def load_weather_data():
for message in data["messages"]:
# Jede Nachricht kann mehrere Wetterstationen enthalten
if isinstance(message, list):
for station_data in message[1:]:
for station_data in message:
station_info = {}
# Überprüfe, ob station_data eine Liste ist
if isinstance(station_data, list):
@@ -33,25 +33,26 @@ def load_weather_data():
# Stelle sicher, dass info ein Dictionary ist
if isinstance(info, dict) and "key" in info:
if info["key"] == "stationNumber":
station_info["stationNumber"] = info["value"]
station_info["stationNumber"] = info.get("value", None)
elif info["key"] == "stationOrSiteName":
station_info["stationName"] = info["value"]
station_info["stationName"] = info.get("value", None)
elif info["key"] == "airTemperature":
station_info["temperature"] = round(info["value"] - 273.15, 2) # Umwandlung von K in °C
station_info["temperature"] = round(info.get("value", 0) - 273.15, 2) # Umwandlung von K in °C
elif info["key"] == "windSpeed":
station_info["windSpeed"] = info["value"]
station_info["windSpeed"] = info.get("value", None)
elif info["key"] == "pressureReducedToMeanSeaLevel":
station_info["pressure"] = info["value"]
station_info["pressure"] = info.get("value", None)
# Füge nur Daten hinzu, wenn sie vollständig sind
if "stationNumber" in station_info:
if "stationNumber" in station_info and station_info["stationNumber"] is not None:
weather_data.append(station_info)
# Sortiere nach stationNumber
weather_data.sort(key=lambda x: x["stationNumber"])
weather_data.sort(key=lambda x: x.get("stationNumber", 0))
return weather_data
# Flask Route für die Hauptseite
@app.route('/')
def index():