create haltestellen if they don't exist

master
0x90.space 2021-12-29 04:32:44 +01:00
parent ab79366ec5
commit a5ef683e32
1 changed files with 9 additions and 1 deletions

View File

@ -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,