1
1
# coding=utf-8
2
2
3
3
import requests
4
- import json
5
4
import datetime
6
5
from time import mktime
7
6
8
7
api_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
11
10
departure_url = "https://www.mvg.de/api/fahrinfo/departure/{id}?footway=0"
12
11
nearby_url = "https://www.mvg.de/api/fahrinfo/location/nearby?latitude={lat}&longitude={lon}"
13
12
routing_url = "https://www.mvg.de/api/fahrinfo/routing/?"
14
13
interruptions_url = "https://www.mvg.de/.rest/betriebsaenderungen/api/interruptions"
15
14
16
15
17
16
def _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
+ )
19
25
return resp .json ()
20
26
21
27
@@ -35,11 +41,8 @@ def _convert_time(time):
35
41
if isinstance (time , datetime .datetime ):
36
42
return int (mktime (time .timetuple ()))* 1000
37
43
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 )
43
46
44
47
45
48
def get_nearby_stations (lat , lon ):
@@ -140,7 +143,7 @@ def get_locations(query):
140
143
141
144
"""
142
145
try :
143
- query = int (query ) # converts station ids to int if thay aren't already
146
+ query = int (query ) # converts station ids to int
144
147
except (ValueError ): # happens if it is a station name
145
148
url = query_url_name .format (name = query )
146
149
else : # happens if it is a station id
@@ -217,7 +220,7 @@ def get_route(start, dest,
217
220
options .append ("maxTravelTimeFootwayToDestination=" +
218
221
str (max_walk_time_to_dest ))
219
222
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
221
224
if isinstance (change_limit , int ):
222
225
options .append ("changeLimit=" + str (change_limit ))
223
226
0 commit comments