From 70e0c367242c7e037b133fabde3e2b8bd4845856 Mon Sep 17 00:00:00 2001 From: SimolZimol <70102430+SimolZimol@users.noreply.github.com> Date: Tue, 10 Sep 2024 14:56:00 +0200 Subject: [PATCH] modified: app.py modified: templates/index.html --- app.py | 47 ++++++++++++-------------- templates/index.html | 79 ++++++++++++++++++++++++++------------------ 2 files changed, 69 insertions(+), 57 deletions(-) diff --git a/app.py b/app.py index 7f77027..9319e99 100644 --- a/app.py +++ b/app.py @@ -22,38 +22,35 @@ def load_weather_data(): weather_data = [] for message in data["messages"]: + # Jede Nachricht kann mehrere Wetterstationen enthalten if isinstance(message, list): - for subset in message[1:]: # Ignoriere den ersten Header-Teil + for station_data in message[1:]: station_info = {} - if isinstance(subset, list): - for item in subset: - # Sicherstellen, dass wir ein Dictionary haben - if isinstance(item, dict): - key = item.get("key") - value = item.get("value") - # Hier relevante Daten extrahieren und speichern - if key == "stationNumber": - station_info["stationNumber"] = value - elif key == "stationOrSiteName": - station_info["stationName"] = value - elif key == "airTemperature": - station_info["temperature"] = round(value - 273.15, 2) # Umrechnung K -> °C - elif key == "relativeHumidity": - station_info["humidity"] = value - elif key == "pressureReducedToMeanSeaLevel": - station_info["pressure"] = value - elif key == "windSpeed": - station_info["windSpeed"] = value - # Füge nur vollständige Einträge hinzu - if "stationNumber" in station_info and 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"] if "stationNumber" in x else None) + weather_data.sort(key=lambda x: x["stationNumber"]) return weather_data - # Flask Route für die Hauptseite @app.route('/') def index(): diff --git a/templates/index.html b/templates/index.html index fa1b5bf..e7dac1d 100644 --- a/templates/index.html +++ b/templates/index.html @@ -3,65 +3,80 @@
-| Stationsnummer | -Stationsname | -Temperatur (°C) | +Station Nummer | +Station Name | +Temperatur (K) | +Taupunkt (K) | Relative Luftfeuchtigkeit (%) | Windgeschwindigkeit (m/s) | -Luftdruck (Pa) |
|---|---|---|---|---|---|---|---|---|---|
| {{ station.stationNumber }} | -{{ station.stationName }} | -{{ station.temperature }} | -{{ station.humidity }} | -{{ station.windSpeed }} | -{{ station.pressure }} | -