With all this wild weather about recently, I decided to update my e-ink display to include watches and warnings. This is based on continuing development of my display Obligatory WeatherFlow e-ink Display shameless plug, I know.
Rain/storm data is setup on my display to be dynamic. The total rain and duration will appear only for the day, the lightning strike data for 3 hours, and the weather alerts until they expire. Here’s an example with hard-set data in the python:
The NWS API, from their website, is free to use for personal use! All you need to find if your appropriate county code and plug it in on the end of this API call https://api.weather.gov/alerts/active?zone=" From there, I wrote code around it to pick out watches and warnings. I really do not care about Special Weather Statements, I’ll see those on my phone anyway. Here’s the code I used - if any developers see any mistakes, feel free to let me know. I am new to python and this was my first real project! I do have a couple other selections in there for later use commented out:
#Get Severe weather data from NWS
response = requests.get("https://api.weather.gov/alerts/active?zone=YOURIDHERE")
nws = response.json()
try:
alert = nws['features'][int(0)]['properties']
event = alert['event']
#urgency = alert['urgency']
#severity = alert['severity']
except IndexError:
print('No NWS Alerts')
alert = None
if alert != None and (event.endswith('Warning') or event.endswith('Watch')):
string_event = event
Later on I make it dynamic:
#Severe Weather Mod
try:
if string_event != None:
alert_file = 'warning.png'
alert_image = Image.open(os.path.join(icondir, alert_file))
template.paste(alert_image, (335, 255))
draw.text((385, 263), string_event, font=font23, fill=black)
except NameError:
print('No Severe Weather')
When the threat clears, it calls off the NWS data, the try except statement does it’s job and the warning triangle/message will fall off. Standard look to follow in reply. Still limited by newbie status.
If anyone has questions, comments, or feedback let me know!