modified: app.py
This commit is contained in:
Binary file not shown.
18
app.py
18
app.py
@@ -64,6 +64,14 @@ def _round_temp(k):
|
|||||||
def get_mosmix_forecast(lat, lon, hours=72):
|
def get_mosmix_forecast(lat, lon, hours=72):
|
||||||
"""Holt MOSMIX-Vorhersage für die nächsten Stunden."""
|
"""Holt MOSMIX-Vorhersage für die nächsten Stunden."""
|
||||||
try:
|
try:
|
||||||
|
# Zeitzone Berlin für alle Anzeige-Timestamps
|
||||||
|
try:
|
||||||
|
import zoneinfo
|
||||||
|
_berlin = zoneinfo.ZoneInfo("Europe/Berlin")
|
||||||
|
except ImportError:
|
||||||
|
import pytz
|
||||||
|
_berlin = pytz.timezone("Europe/Berlin")
|
||||||
|
|
||||||
req = DwdMosmixRequest(parameters=MOSMIX_PARAMS)
|
req = DwdMosmixRequest(parameters=MOSMIX_PARAMS)
|
||||||
nearest = req.filter_by_rank(latlon=(lat, lon), rank=1)
|
nearest = req.filter_by_rank(latlon=(lat, lon), rank=1)
|
||||||
result = nearest.values.all()
|
result = nearest.values.all()
|
||||||
@@ -119,7 +127,7 @@ def get_mosmix_forecast(lat, lon, hours=72):
|
|||||||
wind_dir = float(wind_dir_v) if not _isnan(wind_dir_v) else None
|
wind_dir = float(wind_dir_v) if not _isnan(wind_dir_v) else None
|
||||||
|
|
||||||
forecast.append({
|
forecast.append({
|
||||||
"datetime": date_val,
|
"datetime": pd.Timestamp(date_val).tz_convert(_berlin).tz_localize(None),
|
||||||
"temp_c": temp_c,
|
"temp_c": temp_c,
|
||||||
"wind_kmh": wind_kmh,
|
"wind_kmh": wind_kmh,
|
||||||
"gust_kmh": gust_kmh,
|
"gust_kmh": gust_kmh,
|
||||||
@@ -200,7 +208,7 @@ def wetter():
|
|||||||
station_lon = float(mosmix_station.get("longitude", lon))
|
station_lon = float(mosmix_station.get("longitude", lon))
|
||||||
station_dist = round(haversine(lat, lon, station_lat, station_lon), 1)
|
station_dist = round(haversine(lat, lon, station_lat, station_lon), 1)
|
||||||
|
|
||||||
# "Aktuell" = erste Stunde >= jetzt (UTC), sonst erste verfügbare
|
# "Aktuell" = erste Stunde >= jetzt (Berliner Lokalzeit)
|
||||||
now_utc = _dt.datetime.now(_dt.timezone.utc).replace(tzinfo=None)
|
now_utc = _dt.datetime.now(_dt.timezone.utc).replace(tzinfo=None)
|
||||||
try:
|
try:
|
||||||
import zoneinfo
|
import zoneinfo
|
||||||
@@ -208,12 +216,14 @@ def wetter():
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
import pytz
|
import pytz
|
||||||
berlin = pytz.timezone("Europe/Berlin")
|
berlin = pytz.timezone("Europe/Berlin")
|
||||||
now_local = _dt.datetime.now(berlin).strftime("%H:%M")
|
now_local_dt = _dt.datetime.now(berlin)
|
||||||
|
now_local = now_local_dt.strftime("%H:%M")
|
||||||
|
now_berlin_naive = now_local_dt.replace(tzinfo=None)
|
||||||
current_idx = 0
|
current_idx = 0
|
||||||
for i, h in enumerate(forecast):
|
for i, h in enumerate(forecast):
|
||||||
dt = h["datetime"]
|
dt = h["datetime"]
|
||||||
dt_naive = dt.replace(tzinfo=None) if hasattr(dt, "tzinfo") and dt.tzinfo is not None else dt
|
dt_naive = dt.replace(tzinfo=None) if hasattr(dt, "tzinfo") and dt.tzinfo is not None else dt
|
||||||
if dt_naive >= now_utc:
|
if dt_naive >= now_berlin_naive:
|
||||||
current_idx = i
|
current_idx = i
|
||||||
break
|
break
|
||||||
current = forecast[current_idx]
|
current = forecast[current_idx]
|
||||||
|
|||||||
Reference in New Issue
Block a user