Week ahead in the weather strip, reverse LCD at night

The weekday strip now shows today and the next six days (icon, max, min),
the current temperature and feels-like sit next to the clock, and the rain
graph spans the full width with the hour under every bar. From sunset to
sunrise the whole frame, seconds patch included, is drawn as a reverse LCD.
The rain label is now spelled DÉŠŤ.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
rickzkmandClaude Opus 5.5 committed 2026-10-28 22:40:34 +01:00
1 parent 45508b1b68
commit 6c9a1420d2
10 files changed
+341 -122

No files matched your search

+33 -13
View File
@@ -1,6 +1,6 @@
"""Open-Meteo forecast for Zlín: fetching and parsing (no drawing)."""
from dataclasses import dataclass
from datetime import datetime
from datetime import date, datetime
from enum import Enum
import requests
@@ -19,12 +19,22 @@ class Hour:
mm: float | None
@dataclass(frozen=True)
class Day:
date: date
code: int | None
high: float | None
low: float | None
sunrise: datetime | None # naive local time
sunset: datetime | None
@dataclass(frozen=True)
class Weather:
temp: float | None
feels: float | None
code: int | None
today_max: float | None
today_min: float | None
days: tuple[Day, ...] # as the forecast gives them, today first when fresh
hours: tuple[Hour, ...] # at most WINDOW_HOURS, starting with the hour containing "now"
@@ -61,16 +71,26 @@ def _at(values, i: int):
return values[i]
def _time(value) -> datetime | None:
return datetime.fromisoformat(value) if value else None
def parse_weather(payload: dict, now: datetime) -> Weather:
current = payload.get("current") or {}
daily = payload.get("daily") or {}
hourly = payload.get("hourly") or {}
day = now.strftime("%Y-%m-%d")
days = daily.get("time") or []
d = days.index(day) if day in days else None
today_max = _at(daily.get("temperature_2m_max"), d) if d is not None else None
today_min = _at(daily.get("temperature_2m_min"), d) if d is not None else None
days = tuple(
Day(
date=date.fromisoformat(day),
code=_at(daily.get("weather_code"), i),
high=_at(daily.get("temperature_2m_max"), i),
low=_at(daily.get("temperature_2m_min"), i),
sunrise=_time(_at(daily.get("sunrise"), i)),
sunset=_time(_at(daily.get("sunset"), i)),
)
for i, day in enumerate(daily.get("time") or [])
)
hours: list[Hour] = []
times = hourly.get("time") or []
@@ -86,9 +106,9 @@ def parse_weather(payload: dict, now: datetime) -> Weather:
return Weather(
temp=current.get("temperature_2m"),
feels=current.get("apparent_temperature"),
code=current.get("weather_code"),
today_max=today_max,
today_min=today_min,
days=days,
hours=tuple(hours),
)
@@ -97,11 +117,11 @@ def fetch_weather(now: datetime, get=requests.get) -> Weather:
params = {
"latitude": LAT,
"longitude": LON,
"current": "temperature_2m,weather_code",
"current": "temperature_2m,weather_code,apparent_temperature",
"hourly": "precipitation_probability,precipitation",
"daily": "temperature_2m_max,temperature_2m_min",
"daily": "weather_code,temperature_2m_max,temperature_2m_min,sunrise,sunset",
"timezone": TIMEZONE,
"forecast_days": 2,
"forecast_days": 7,
}
response = get(URL, params=params, timeout=10)
response.raise_for_status()