Skip to content

Instantly share code, notes, and snippets.

@adamsheridan
Last active August 29, 2015 14:04
Show Gist options
  • Save adamsheridan/c91f604d4c184b7a28ba to your computer and use it in GitHub Desktop.
Save adamsheridan/c91f604d4c184b7a28ba to your computer and use it in GitHub Desktop.
TFL TubeStatus Python CLI e.g python tfl.py 8
from BeautifulSoup import BeautifulSoup
import urllib2, sys
response = urllib2.urlopen('http://cloud.tfl.gov.uk/TrackerNet/LineStatus');
xml = response.read();
soup = BeautifulSoup(xml);
try:
lineId = sys.argv[1]
except IndexError:
lineId = 6
print('No line id specified, using: 6')
def lineStatus(id):
lines = soup.arrayoflinestatus.findAll('linestatus', {'id' : id})
if len(lines) == 0:
print 'Line does not exist'
else:
for line in lines:
name = line.find('line')['name']
status = line.find('status')['description']
print 'The {:1} line currently has a status of {:2}'.format(name, status)
lineStatus(lineId)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment