From a5ef683e32c21a2cb65ae976a561d1e2feca1909 Mon Sep 17 00:00:00 2001 From: "0x90.space" Date: Wed, 29 Dec 2021 04:32:44 +0100 Subject: [PATCH] create haltestellen if they don't exist --- src/ticketfrei3/application.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ticketfrei3/application.py b/src/ticketfrei3/application.py index 4b14853..e296410 100644 --- a/src/ticketfrei3/application.py +++ b/src/ticketfrei3/application.py @@ -62,7 +62,7 @@ async def fetch_haltestellen(client: ClientSession) -> None: async def fetch_fahrten(client: ClientSession) -> None: for zweig in ("bus", "tram", "ubahn"): response = await client.get( - "https://start.vag.de/dm/api/v1/fahrten.json/%s?timespan=120" % zweig + "https://start.vag.de/dm/api/v1/fahrten.json/%s?timespan=70" % zweig ) fahrten = from_json(await response.text()) for fahrt in fahrten["Fahrten"]: @@ -82,6 +82,14 @@ async def fetch_fahrten(client: ClientSession) -> None: .using_db(connection) .first() ) + if haltestelle is None: + haltestelle = Haltestelle( + id=halt["VGNKennung"], + name=halt["Haltestellenname"], + longitude=halt.get("Longitude"), + latitude=halt.get("Latitude"), + ) + await haltestelle.save(using_db=connection) await Halt( fahrt=fahrt, haltestelle=haltestelle,