Created
June 7, 2012 10:52
-
-
Save Svenito/2888187 to your computer and use it in GitHub Desktop.
Get the London tube status on your CLI & Conky
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
#!/usr/bin/env python2.6 | |
import urllib | |
from xml.dom import minidom | |
from optparse import OptionParser | |
status_url = "http://api.tubeupdates.com/?method=get.status&lines=%s&format=xml" | |
def main(lines, show_message): | |
url = status_url % ','.join(lines) | |
dom = minidom.parse(urllib.urlopen(url)) | |
for line in dom.getElementsByTagName('line'): | |
line_name = line.getElementsByTagName('name')[0].firstChild.data | |
status = line.getElementsByTagName('status')[0].firstChild.data | |
print line_name, status | |
if cmp(status, "good service") and show_message: | |
messages = line.getElementsByTagName('messages')[0] | |
for message in messages.getElementsByTagName('message'): | |
print message.firstChild.data | |
if __name__ == "__main__": | |
parser = OptionParser() | |
parser.add_option("-s", "--status", | |
action="store_false", dest="status", default=True, | |
help="Print only status and line name.") | |
(options, args) = parser.parse_args() | |
main(args, options.status) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
related: http://www.unlogic.co.uk/blog/2012/06/tube-status/