Created
March 1, 2011 03:29
-
-
Save th0ma5w/848563 to your computer and use it in GitHub Desktop.
play a sound when there's a tornado warning near me
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/python | |
# WARNING: If you want to use it, don't rely on it, and you'd have to edit it to get to work for you, wherever you are, if you're in the US. | |
from lxml import etree | |
from urllib2 import urlopen | |
from subprocess import Popen, PIPE | |
COUNTY="franklin" | |
#COUNTY="union" | |
oh="http://www.weather.gov/wwarss-tst/oh.php?x=0" | |
w=etree.fromstring(urlopen(oh).read()) | |
entries = w.findall('{http://www.w3.org/2005/Atom}entry') | |
values=[] | |
for x in entries: | |
thisentry = {} | |
thisentry.update({'msgType': list(x.findall('{urn:oasis:names:tc:emergency:cap:1.1}msgType')[0].itertext())[0]}) | |
thisentry.update({'urgency': list(x.findall('{urn:oasis:names:tc:emergency:cap:1.1}urgency')[0].itertext())[0]}) | |
thisentry.update({'severity': list(x.findall('{urn:oasis:names:tc:emergency:cap:1.1}severity')[0].itertext())[0]}) | |
thisentry.update({'areaDesc': list(x.findall('{urn:oasis:names:tc:emergency:cap:1.1}areaDesc')[0].itertext())[0]}) | |
thisentry.update({'title': list(x.findall('{http://www.w3.org/2005/Atom}title')[0].itertext())[0]}) | |
values.append(thisentry) | |
county = [x for x in values if x['areaDesc'].lower().__contains__(COUNTY)] | |
immediate_extreme = [x for x in county if x['urgency'].lower()=='immediate' and x['severity'].lower()=='extreme'] | |
if len(immediate_extreme) > 0: | |
output = output = Popen(["/home/thomas/loopffplay.sh", "/home/thomas/emergency.wav"], stdout=PIPE).communicate()[0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
heh, some voodoo and redundant code, i was tired! :P