-
Notifications
You must be signed in to change notification settings - Fork 1
/
SLApi.py
24 lines (21 loc) · 1.08 KB
/
SLApi.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import urllib
import datetime
import config
import json
class SLApi:
deviationBaseURL = 'https://api.trafiklab.se/sl/storningsinfo/GetDeviations.json'
def executeDeviationCall(self,lines,transportMode):
today = datetime.date.today()
if lines is not None:
url = self.deviationBaseURL +'?key={0}&fromDate={1}&toDate={2}&lineNumber={3}&transportMode={4}'.format(config.DEVIATION_API_KEY,today,today,lines,transportMode)
if lines is None:
url = self.deviationBaseURL +'?key={0}&fromDate={1}&toDate={2}&transportMode={3}'.format(config.DEVIATION_API_KEY,today,today,transportMode)
apiData = urllib.urlopen(url).read()
jsonData = json.loads(apiData)
result = self.mapDeviationResult(jsonData)
return result
def mapDeviationResult(self,response):
result = []
for deviation in response["GetDeviationsResponse"]["GetDeviationsResult"]["aWCFDeviation"]:
result.append({'Guid':deviation['aDevCaseGid'],'Header':deviation['aHeader'],'Details':deviation['aDetails'],'Updated':deviation['aUpdated'], 'Main': deviation['aMainNews']})
return result