Skip to content

Instantly share code, notes, and snippets.

@cnorthwood
Created February 17, 2011 16:09
Show Gist options
  • Save cnorthwood/832001 to your computer and use it in GitHub Desktop.
Save cnorthwood/832001 to your computer and use it in GitHub Desktop.
import urllib
from xml.dom import minidom
class TubeStatusProvider():
LINESTATUS_URL = 'http://cloud.tfl.gov.uk/TrackerNet/LineStatus'
def get_status(self):
statuses = []
status_xml = minidom.parse(urllib.urlopen(self.LINESTATUS_URL))
for node in status_xml.documentElement.childNodes:
if node.nodeType == node.ELEMENT_NODE and node.tagName == 'LineStatus':
line_status = {
'disruption_reason': node.getAttribute('StatusDetails'),
}
for child in node.childNodes:
if child.nodeType == child.ELEMENT_NODE and child.tagName == 'Line':
line_status['line_name'] = child.getAttribute('Name')
elif child.nodeType == child.ELEMENT_NODE and child.tagName == 'Status':
line_status['status'] = child.getAttribute('Description')
statuses.append(line_status)
return statuses
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment