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

Commit 43c4ef2

Browse files
authored
Merge pull request #4 from paul0x1C/master
Use module-level function inside Station class
2 parents d4ae3dd + 7356ecf commit 43c4ef2

File tree

1 file changed

+9
-19
lines changed

1 file changed

+9
-19
lines changed

mvg_api/__init__.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -283,25 +283,15 @@ class Station:
283283
"""
284284

285285
def __init__(self, station):
286-
if isinstance(station, str):
287-
self.station_id = get_id_for_station(station)
288-
if self.station_id is None:
289-
raise NameError("No matching station found")
290-
elif isinstance(station, int):
291-
self.station_id = station
286+
matching_stations = get_stations(station)
287+
if matching_stations == []:
288+
raise NameError("No matching station found")
292289
else:
293-
raise ValueError("Please provide a Station Name or ID")
290+
self.id = matching_stations[0]["id"]
291+
self.name = matching_stations[0]["name"]
294292

295293
def get_departures(self):
296-
"""Gets the departures for the station object.
297-
Pretty much the same like module-level-:func:`get_departures`
298-
"""
299-
url = departure_url.format(id=str(self.station_id))
300-
departures = _perform_api_request(url)['departures']
301-
for departure in departures:
302-
# For some reason, mvg gives you a Unix timestamp in milliseconds.
303-
# Here, we convert it to a datetime object
304-
time = _convert_time(departure['departureTime'])
305-
relative_time = time - datetime.datetime.now()
306-
departure[u'departureTimeMinutes'] = relative_time.seconds // 60
307-
return departures
294+
return get_departures(self.id)
295+
296+
def __repr__(self):
297+
return "Station(id=%s, name='%s')" % (self.id, self.name)

0 commit comments

Comments
 (0)