11# coding=utf-8
22
33import requests
4- import json
54import datetime
65from time import mktime
76
87api_key = "5af1beca494712ed38d313714d4caff6"
9- query_url_name = "https://www.mvg.de/api/fahrinfo/location/queryWeb?q={name}" # for station names
10- query_url_id = "https://www.mvg.de/api/fahrinfo/location/query?q={id}" # for station ids
8+ query_url_name = "https://www.mvg.de/api/fahrinfo/location/queryWeb?q={name}" # for station names
9+ query_url_id = "https://www.mvg.de/api/fahrinfo/location/query?q={id}" # for station ids
1110departure_url = "https://www.mvg.de/api/fahrinfo/departure/{id}?footway=0"
1211nearby_url = "https://www.mvg.de/api/fahrinfo/location/nearby?latitude={lat}&longitude={lon}"
1312routing_url = "https://www.mvg.de/api/fahrinfo/routing/?"
1413interruptions_url = "https://www.mvg.de/.rest/betriebsaenderungen/api/interruptions"
1514
1615
1716def _perform_api_request (url ):
18- resp = requests .get (url , headers = {'X-MVG-Authorization-Key' : api_key , 'User-Agent' : 'python-mvg-api/1 (+https://github.com/leftshift/python_mvg_api)' , 'Accept' : 'application/json' })
17+ resp = requests .get (
18+ url ,
19+ headers = {
20+ 'X-MVG-Authorization-Key' : api_key ,
21+ 'User-Agent' : 'python-mvg-api/1 (+https://github.com/leftshift/python_mvg_api)' ,
22+ 'Accept' : 'application/json'
23+ }
24+ )
1925 return resp .json ()
2026
2127
@@ -35,11 +41,8 @@ def _convert_time(time):
3541 if isinstance (time , datetime .datetime ):
3642 return int (mktime (time .timetuple ()))* 1000
3743 else :
38- try :
39- timestamp = time / 1000
40- return datetime .datetime .fromtimestamp (timestamp )
41- except Exception as e :
42- raise
44+ timestamp = time / 1000
45+ return datetime .datetime .fromtimestamp (timestamp )
4346
4447
4548def get_nearby_stations (lat , lon ):
@@ -140,7 +143,7 @@ def get_locations(query):
140143
141144 """
142145 try :
143- query = int (query ) # converts station ids to int if thay aren't already
146+ query = int (query ) # converts station ids to int
144147 except (ValueError ): # happens if it is a station name
145148 url = query_url_name .format (name = query )
146149 else : # happens if it is a station id
@@ -217,7 +220,7 @@ def get_route(start, dest,
217220 options .append ("maxTravelTimeFootwayToDestination=" +
218221 str (max_walk_time_to_dest ))
219222
220- if change_limit is not None : # 'if change_limit:' would not work for 0
223+ if change_limit is not None : # 'if change_limit:' would not work for 0
221224 if isinstance (change_limit , int ):
222225 options .append ("changeLimit=" + str (change_limit ))
223226
0 commit comments