Last active
August 29, 2015 14:04
-
-
Save adamsheridan/c91f604d4c184b7a28ba to your computer and use it in GitHub Desktop.
TFL TubeStatus Python CLI e.g python tfl.py 8
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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