modified: app.py
This commit is contained in:
40
app.py
40
app.py
@@ -24,24 +24,28 @@ def load_weather_data():
|
||||
|
||||
for message in data["messages"]:
|
||||
# Jede Nachricht kann mehrere Wetterstationen enthalten
|
||||
for station_data in message[1:]:
|
||||
station_info = {}
|
||||
# Extrahiere wichtige Informationen wie Stationnummer, Name, Temperatur, Windgeschwindigkeit usw.
|
||||
for info in station_data:
|
||||
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"]
|
||||
|
||||
# Füge nur Daten hinzu, wenn sie vollständig sind
|
||||
if "stationNumber" in station_info:
|
||||
weather_data.append(station_info)
|
||||
if isinstance(message, list):
|
||||
for station_data in message[1:]:
|
||||
station_info = {}
|
||||
# Überprüfe, ob station_data eine Liste ist
|
||||
if isinstance(station_data, list):
|
||||
for info in station_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"]
|
||||
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"]
|
||||
|
||||
# Füge nur Daten hinzu, wenn sie vollständig sind
|
||||
if "stationNumber" in station_info:
|
||||
weather_data.append(station_info)
|
||||
|
||||
# Sortiere nach stationNumber
|
||||
weather_data.sort(key=lambda x: x["stationNumber"])
|
||||
|
||||
Reference in New Issue
Block a user