Created
February 17, 2011 16:09
-
-
Save cnorthwood/832001 to your computer and use it in GitHub Desktop.
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
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