create haltestellen if they don't exist
This commit is contained in:
parent
ab79366ec5
commit
a5ef683e32
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue