Schweiz: alten Fahrplan ohne Trams nicht mehr laden, nur weil die Echtzeit noch auf ihn verweist
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01X48pE4bzjHej8w9HyZXCjb
This commit is contained in:
+15
-4
@@ -16,7 +16,7 @@ from fastapi.staticfiles import StaticFiles
|
||||
|
||||
from . import config as C
|
||||
from . import border, realtime
|
||||
from .feed import TZ, Feed
|
||||
from .feed import TZ, Feed, read, route_mode
|
||||
|
||||
log = logging.getLogger("trainpulse")
|
||||
STEP, STEPS = 2, 6 # Gleisverlauf für die nächsten 12 s (Abruf alle 5 s, Berechnung alle 3 s -> Reserve)
|
||||
@@ -68,6 +68,13 @@ def loop(every: float, fn, *args):
|
||||
threading.Thread(target=run, daemon=True, name=fn.__name__).start()
|
||||
|
||||
|
||||
def feed_format(path: Path, meta: dict) -> int:
|
||||
"""Aufbereitungs-Format; ältere Ordner ohne Angabe: 2, wenn Trams/U-Bahnen drin sind."""
|
||||
if "format" in meta:
|
||||
return meta["format"]
|
||||
return 2 if any(route_mode(r[h["route_type"]]) != "rail" for h, r in read(path / "routes.txt")) else 1
|
||||
|
||||
|
||||
def watch_feeds():
|
||||
"""Lädt je Quelle den passenden Fahrplan: den, auf den sich die Echtzeitdaten beziehen (Schweiz:
|
||||
die schalten erst um 15 Uhr auf einen neuen Fahrplan um), sonst den neusten."""
|
||||
@@ -77,11 +84,15 @@ def watch_feeds():
|
||||
found[src.name] = sorted(m.parent.name for m in (C.FEEDS_DIR / src.name).glob("*/meta.json"))
|
||||
src.on_disk = bool(found[src.name])
|
||||
for src in S.sources.values():
|
||||
ready = found[src.name]
|
||||
if not ready:
|
||||
if not found[src.name]:
|
||||
continue
|
||||
metas = {v: json.loads((C.FEEDS_DIR / src.name / v / "meta.json").read_text()) for v in found[src.name]}
|
||||
# nur Versionen im neusten Aufbereitungs-Format (sonst z. B. alter Fahrplan ohne Trams, nur weil
|
||||
# die Echtzeit sich noch auf ihn bezieht)
|
||||
fmts = {v: feed_format(C.FEEDS_DIR / src.name / v, m) for v, m in metas.items()}
|
||||
ready = [v for v in found[src.name] if fmts[v] == max(fmts.values())]
|
||||
want = src.rt_version if src.rt_version in ready else ready[-1]
|
||||
meta = json.loads((C.FEEDS_DIR / src.name / want / "meta.json").read_text())
|
||||
meta = metas[want]
|
||||
if (src.feed and src.feed.version == want and src.feed.covers(today + dt.timedelta(days=1))
|
||||
and src.feed.meta.get("prepared_at") == meta.get("prepared_at")): # gleiche Version neu aufbereitet?
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user