feat: weather view and preview script
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
1 parent
37065a5fba
commit
65843aa958
5 files changed
+392
No files matched your search
+60
@@ -0,0 +1,60 @@
|
||||
"""Render every view with fake data to docs/previews/*.png (no screen, no network needed)."""
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
from PIL import Image
|
||||
|
||||
from lcdkit import H, W
|
||||
from weather_data import Hour, Weather
|
||||
from weather_view import WeatherView
|
||||
|
||||
OUT = Path(__file__).parent / "docs" / "previews"
|
||||
NOW = datetime(2026, 10, 22, 14, 32, 8) # a Thursday afternoon
|
||||
|
||||
|
||||
class FakePoller:
|
||||
def __init__(self, value, age: float | None = 60.0):
|
||||
self.value, self.version, self.failures, self._age = value, 1 if value is not None else 0, 0, age
|
||||
|
||||
def age(self):
|
||||
return self._age
|
||||
|
||||
def start(self):
|
||||
pass
|
||||
|
||||
def stop(self):
|
||||
pass
|
||||
|
||||
|
||||
def fake_weather(temp=14.2, rain=(0, 0, 10, 20, 40, 70, 60, 50, 30, 20, 10, 0), code=2) -> Weather:
|
||||
hours = tuple(Hour(datetime(2026, 10, 22, 14 + i, 0) if 14 + i < 24 else datetime(2026, 10, 23, 14 + i - 24, 0),
|
||||
p, 0.3) for i, p in enumerate(rain))
|
||||
return Weather(temp=temp, code=code, today_max=16.0, today_min=7.0, hours=hours)
|
||||
|
||||
|
||||
def sheet(images: list[Image.Image], columns: int = 2) -> Image.Image:
|
||||
rows = -(-len(images) // columns)
|
||||
out = Image.new("RGB", (columns * W + (columns - 1) * 20, rows * H + (rows - 1) * 20), (40, 40, 40))
|
||||
for i, img in enumerate(images):
|
||||
out.paste(img, ((i % columns) * (W + 20), (i // columns) * (H + 20)))
|
||||
return out
|
||||
|
||||
|
||||
def weather_previews() -> Image.Image:
|
||||
cases = [
|
||||
FakePoller(fake_weather()),
|
||||
FakePoller(fake_weather(temp=-3.4, rain=(100,) * 12, code=71)),
|
||||
FakePoller(None, age=None),
|
||||
FakePoller(fake_weather(code=95), age=7200.0),
|
||||
]
|
||||
return sheet([WeatherView(p).render(NOW) for p in cases])
|
||||
|
||||
|
||||
def main() -> None:
|
||||
OUT.mkdir(parents=True, exist_ok=True)
|
||||
weather_previews().save(OUT / "weather.png")
|
||||
print(OUT / "weather.png")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user