Skip to content

Instantly share code, notes, and snippets.

@romanz
Created October 22, 2011 13:38
Show Gist options
  • Save romanz/1306020 to your computer and use it in GitHub Desktop.
Save romanz/1306020 to your computer and use it in GitHub Desktop.
Extract weather information (for conky)
#!/usr/bin/python
# Usage for .conkyrc:
# ${execi 15 ~/weather.py 40155}
import sys
import re
from urllib2 import urlopen
url = 'http://rss.wunderground.com/auto/rss_full/global/stations/'
station_id, = sys.argv[1:]
u = urlopen(url + station_id + '.xml?units=metric')
data = u.read()
m = re.search('CDATA\[(.*?)\]', data) # Extract current data
s, = m.groups()
s = re.sub('<img .*?>', '', s) # Remove images
s = s.replace('&deg;', '') # Remove degree sign
s = s.replace(' | ', '\n') # Split into lines
sys.stdout.write(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment