-
Notifications
You must be signed in to change notification settings - Fork 0
/
capture_transit_status.py
43 lines (35 loc) · 1.15 KB
/
capture_transit_status.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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from flask import Flask
import urllib2
import xml.etree.ElementTree as ET
import json
app = Flask(__name__)
@app.route('/nycstatus.html')
def status():
currentStatus = subwayStatus()
message = ""
for k,v in currentStatus.iteritems():
message += k + "," + v + "\n"
return message
def subwayStatus():
currentStatus = {}
file = urllib2.urlopen('http://web.mta.info/status/serviceStatus.txt')
data = file.read()
file.close()
root = ET.fromstring(data)
for child in root[2]:
currentStatus[child[0].text] = child[1].text
return currentStatus
@app.route('/lonstatus.html')
def londonstatus():
app_id = 'YOURID' # Register for an app id and key at https://api.tfl.gov.uk/
app_key = 'YOURKEY'
file = urllib2.urlopen('https://api.tfl.gov.uk/Line/Mode/tube,overground,dlr/Status?detail=False&app_id=' + app_id + '&app_key=' + app_key)
data = file.read()
file.close()
parsedData = json.loads(data)
message = ""
for line in parsedData:
message += line['id'] + ',' + line['lineStatuses'][0]['statusSeverityDescription'] + '\n'
return message
if __name__ == "__main__":
app.run()