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

Commit 57d8bb7

Browse files
author
Paul
committed
we now have to use two different query urls: one for station names and a sperate one for station ids
1 parent ce3f650 commit 57d8bb7

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

mvg/__init__.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
from time import mktime
77

88
api_key = "5af1beca494712ed38d313714d4caff6"
9-
query_url = "https://www.mvg.de/fahrinfo/api/location/query?q="
9+
query_url_name = "https://www.mvg.de/fahrinfo/api/location/queryWeb?q=" #for station names
10+
query_url_id = "https://www.mvg.de/fahrinfo/api/location/query?q=" #for station ids
1011
departure_url = "https://www.mvg.de/fahrinfo/api/departure/"
1112
departure_url_postfix = "?footway=0"
1213
nearby_url = "https://www.mvg.de/fahrinfo/api/location/nearby"
@@ -137,10 +138,13 @@ def get_locations(query):
137138
]
138139
139140
"""
140-
if isinstance(query, int):
141-
url = query_url + str(query)
142-
else:
143-
url = query_url + query
141+
try:
142+
query = int(query) # converts station ids to int if thay aren't already
143+
except(ValueError): # happens if it is a station name
144+
url = query_url_name + query
145+
else: # happens if it is a station id
146+
url = query_url_id + str(query)
147+
144148
results = _perform_api_request(url)
145149
return results["locations"]
146150

0 commit comments

Comments
 (0)