Skip to content
This repository was archived by the owner on Jun 29, 2023. It is now read-only.

Commit 88bf119

Browse files
authored
Merge pull request #26 from aaearon/footway
add time offset to have api pre-filter departures
2 parents a32176b + 188dad6 commit 88bf119

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

mvg_api/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
query_url_name = "https://www.mvg.de/api/fahrinfo/location/queryWeb?q={name}" # for station names
88
query_url_id = "https://www.mvg.de/api/fahrinfo/location/query?q={id}" # for station ids
9-
departure_url = "https://www.mvg.de/api/fahrinfo/departure/{id}?footway=0"
9+
departure_url = "https://www.mvg.de/api/fahrinfo/departure/{id}?footway={offset}"
1010
nearby_url = "https://www.mvg.de/api/fahrinfo/location/nearby?latitude={lat}&longitude={lon}"
1111
routing_url = "https://www.mvg.de/api/fahrinfo/routing/?"
1212
interruptions_url = "https://www.mvg.de/.rest/betriebsaenderungen/api/interruptions"
@@ -308,8 +308,9 @@ def get_route(start, dest,
308308
return results["connectionList"]
309309

310310

311-
def get_departures(station_id):
312-
"""Get the next departures for `station_id`.
311+
def get_departures(station_id, timeoffset=0):
312+
"""Get the next departures for `station_id`. Optionally, define `timeoffset`
313+
to not show departures sooner than a number of minutes.
313314
314315
Change in 1.3.2: accepts both 'old-style' integer IDs which were used
315316
by the API before this version and the new string IDs which
@@ -343,7 +344,7 @@ def get_departures(station_id):
343344
raise TypeError("Please give the int station_id of the station.\
344345
You can find it out by running \
345346
get_id_for_station('Station name')")
346-
url = departure_url.format(id=station_id)
347+
url = departure_url.format(id=station_id, offset=timeoffset)
347348
departures = _perform_api_request(url)['departures']
348349
for departure in departures:
349350
# For some reason, mvg gives you a Unix timestamp, but in milliseconds.
@@ -386,8 +387,8 @@ def __init__(self, station):
386387
self.latitude = matching_stations[0]["latitude"]
387388
self.longitude = matching_stations[0]["longitude"]
388389

389-
def get_departures(self):
390-
return get_departures(self.id)
390+
def get_departures(self, timeoffset=0):
391+
return get_departures(self.id, timeoffset)
391392

392393
def __repr__(self):
393394
return "Station(id=%s, name='%s')" % (self.id, self.name)

0 commit comments

Comments
 (0)