Skip to content

Instantly share code, notes, and snippets.

@klaussilveira
Created June 26, 2020 13:48
Show Gist options
  • Save klaussilveira/2c51943fbf8e400ab81033b3dae1e143 to your computer and use it in GitHub Desktop.
Save klaussilveira/2c51943fbf8e400ab81033b3dae1e143 to your computer and use it in GitHub Desktop.
Check for hurricanes
import xml.etree.ElementTree as ET
import urllib.request
import re
namespaces = {'nhc': 'http://www.nhc.noaa.gov'}
# Drill: https://www.nhc.noaa.gov/rss_examples/index-at-20130605.xml
xml = urllib.request.urlopen('https://www.nhc.noaa.gov/index-at.xml').read()
root = ET.fromstring(xml)
hurricane = root[0].find('item/nhc:Cyclone', namespaces)
if hurricane is None:
print('No hurricanes.')
exit(0)
print('\033[31mWARNING!\n\033[37m')
print('{:s} {:s} at {:s}, on {:s} moving {:s} ({:s})\n'.format(
hurricane.find('nhc:type', namespaces).text,
hurricane.find('nhc:name', namespaces).text,
hurricane.find('nhc:center', namespaces).text,
hurricane.find('nhc:datetime', namespaces).text,
hurricane.find('nhc:movement', namespaces).text,
hurricane.find('nhc:pressure', namespaces).text))
print('\033[34m' + hurricane.find('nhc:headline', namespaces).text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment