Two new views, picked from mockups. `sky`: a star chart of the sky over Zlín as seen lying on your back, with the planets, the moon in its phase, tonight's darkness, cloud for the next 12 hours and the next visible ISS pass. `iss`: a dotted world map with day and night, the ISS and its ground track, and the next pass over Zlín with the cloud cover for that hour. Positions are calculated locally with ephem; only the ISS orbit (CelesTrak, every 6 h, retried gently) and cloud cover (Open-Meteo) are fetched. The poller gained a per-source retry delay for that. Co-Authored-By: Claude Opus 5.5 <[email protected]>
65 lines
1.7 KiB
Python
65 lines
1.7 KiB
Python
"""The views the container can show, selected by the VIEW env var."""
|
|
from typing import Callable
|
|
|
|
from iss_view import IssView
|
|
from poller import Poller
|
|
from server_view import ServerView
|
|
from sky_data import fetch_clouds, fetch_tle
|
|
from sky_view import SkyView
|
|
from stats_data import StatsReader
|
|
from timeutil import local_now
|
|
from view import View
|
|
from weather_data import fetch_weather
|
|
from weather_view import WeatherView
|
|
|
|
WEATHER_REFRESH_S = 15 * 60
|
|
SERVER_REFRESH_S = 1
|
|
TLE_REFRESH_S = 6 * 3600 # CelesTrak updates the elements a few times a day and asks not to be polled hard
|
|
TLE_RETRY_S = 30 * 60
|
|
CLOUDS_REFRESH_S = 15 * 60
|
|
|
|
|
|
class UnknownView(Exception):
|
|
def __init__(self, name: str, valid: list[str]) -> None:
|
|
super().__init__(f"unknown view {name!r}; valid views: {', '.join(valid)}")
|
|
self.name = name
|
|
self.valid = valid
|
|
|
|
|
|
def _weather() -> View:
|
|
return WeatherView(Poller(lambda: fetch_weather(local_now()), WEATHER_REFRESH_S))
|
|
|
|
|
|
def _server() -> View:
|
|
return ServerView(Poller(StatsReader().read, SERVER_REFRESH_S))
|
|
|
|
|
|
def _sky_pollers() -> tuple[Poller, Poller]:
|
|
return (Poller(fetch_tle, TLE_REFRESH_S, retry=TLE_RETRY_S),
|
|
Poller(fetch_clouds, CLOUDS_REFRESH_S))
|
|
|
|
|
|
def _sky() -> View:
|
|
return SkyView(*_sky_pollers())
|
|
|
|
|
|
def _iss() -> View:
|
|
return IssView(*_sky_pollers())
|
|
|
|
|
|
# To add a view: write the module, add one entry here, add a README line.
|
|
REGISTRY: dict[str, Callable[[], View]] = {
|
|
"weather": _weather,
|
|
"server": _server,
|
|
"sky": _sky,
|
|
"iss": _iss,
|
|
}
|
|
|
|
|
|
def make_view(name: str) -> View:
|
|
try:
|
|
factory = REGISTRY[name]
|
|
except KeyError:
|
|
raise UnknownView(name, sorted(REGISTRY)) from None
|
|
return factory()
|