Skip to content

Instantly share code, notes, and snippets.

@dbehnke
Last active August 22, 2021 21:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbehnke/8748328 to your computer and use it in GitHub Desktop.
Save dbehnke/8748328 to your computer and use it in GitHub Desktop.
Severe weather alert grab from NOAA - http://alerts.weather.gov/
feedparser
requests
import feedparser
import requests
import xml.etree.ElementTree as ET
# find your specific url you want to monitor at http://alerts.weather.gov/
# this one is for macomb county, michigan
url = 'http://alerts.weather.gov/cap/wwaatmget.php?x=MIC099&y=0'
feed = feedparser.parse(url)
for f in feed.entries:
details_url = f['link']
r = requests.get(details_url)
root = ET.fromstring(r.text)
info = root.find('{urn:oasis:names:tc:emergency:cap:1.1}info')
weatherinfo = {}
weatherinfo['description'] = (
info.find('{urn:oasis:names:tc:emergency:cap:1.1}description').text)
weatherinfo['urgency'] = (
info.find('{urn:oasis:names:tc:emergency:cap:1.1}urgency').text)
weatherinfo['severity'] = (
info.find('{urn:oasis:names:tc:emergency:cap:1.1}severity').text)
weatherinfo['certainty'] = (
info.find('{urn:oasis:names:tc:emergency:cap:1.1}certainty').text)
weatherinfo['eventCode'] = (
info.find('{urn:oasis:names:tc:emergency:cap:1.1}eventCode').text)
weatherinfo['effective'] = (
info.find('{urn:oasis:names:tc:emergency:cap:1.1}effective').text)
weatherinfo['expires'] = (
info.find('{urn:oasis:names:tc:emergency:cap:1.1}expires').text)
weatherinfo['senderName'] = (
info.find('{urn:oasis:names:tc:emergency:cap:1.1}senderName').text)
weatherinfo['headline'] = (
info.find('{urn:oasis:names:tc:emergency:cap:1.1}headline').text)
weatherinfo['description'] = (
info.find('{urn:oasis:names:tc:emergency:cap:1.1}description').text)
weatherinfo['instruction'] = (
info.find('{urn:oasis:names:tc:emergency:cap:1.1}instruction').text)
weatherinfo['parameter'] = (
info.find('{urn:oasis:names:tc:emergency:cap:1.1}parameter').text)
print(weatherinfo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment