Created
October 22, 2011 13:38
-
-
Save romanz/1306020 to your computer and use it in GitHub Desktop.
Extract weather information (for conky)
This file contains hidden or 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/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('°', '') # 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