Skip to content

Instantly share code, notes, and snippets.

@th0ma5w
Created March 1, 2011 03:29
Show Gist options
  • Save th0ma5w/848563 to your computer and use it in GitHub Desktop.
Save th0ma5w/848563 to your computer and use it in GitHub Desktop.
play a sound when there's a tornado warning near me
#!/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]
@th0ma5w
Copy link
Author

th0ma5w commented Mar 1, 2011

heh, some voodoo and redundant code, i was tired! :P

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