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

Commit 7dcb9b9

Browse files
committed
add function to get lines served for a station
1 parent a32176b commit 7dcb9b9

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

mvg_api/__init__.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,43 @@ def get_departures(station_id):
358358
return departures
359359

360360

361+
def get_lines(station_id):
362+
"""Get the lines being served for `station_id`.
363+
364+
Change in 1.3.2: accepts both 'old-style' integer IDs which were used
365+
by the API before this version and the new string IDs which
366+
look like `de:09162:6`.
367+
368+
To get the `station_id` associated with a station name,
369+
use :func:`get_id_for_station`.
370+
371+
Returns a list like::
372+
373+
[
374+
{
375+
"destination" : "Aying",
376+
"sev" : false,
377+
"partialNet" : "ddb",
378+
"product" : "SBAHN",
379+
"lineNumber" : "S7",
380+
"divaId" : "92M07"
381+
},
382+
]
383+
384+
Note: The api seemingly only returns a single object per
385+
line served, meaning that both directions of a line are
386+
represented only by a single line in the response.
387+
"""
388+
if isinstance(station_id, int):
389+
station_id = _convert_id(station_id)
390+
elif not _station_sanity_check(station_id):
391+
raise TypeError("Please give the int station_id of the station.\
392+
You can find it out by running \
393+
get_id_for_station('Station name')")
394+
url = departure_url.format(id=station_id)
395+
return _perform_api_request(url)['servingLines']
396+
397+
361398
def get_interruptions():
362399
url = interruptions_url
363400
interruptions = _perform_api_request(url)
@@ -389,5 +426,8 @@ def __init__(self, station):
389426
def get_departures(self):
390427
return get_departures(self.id)
391428

429+
def get_lines(self):
430+
return get_lines(self.id)
431+
392432
def __repr__(self):
393433
return "Station(id=%s, name='%s')" % (self.id, self.name)

0 commit comments

Comments
 (0)