Skip to content

Instantly share code, notes, and snippets.

@Svenito
Created June 7, 2012 10:52
Show Gist options
  • Save Svenito/2888187 to your computer and use it in GitHub Desktop.
Save Svenito/2888187 to your computer and use it in GitHub Desktop.
Get the London tube status on your CLI & Conky
#!/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)
@Svenito
Copy link
Author

Svenito commented Jun 7, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment