munin-contrib/plugins/weather/weather_press_

45 lines
1.2 KiB
Python
Executable File

#!/usr/bin/env python3
"""
munin US NOAA weather plugin (https://tgftp.nws.noaa.gov)
Draws pressure in hPa.
Copy/link file as 'weather_pressure_CODE', like: weather_pressure_LOWW for Austria, Vienna.
Get the code by going to https://tgftp.nws.noaa.gov, selecting your
location, and copying the code from the address bar of your browser; should
be something like CODE.html.
Linux users might need to adjust the shebang.
"""
import sys
from urllib.request import urlopen
import re
url = 'https://tgftp.nws.noaa.gov/data/observations/metar/decoded/%s.TXT'
re_hpa = re.compile(r'Pressure.*\((\d+) hPa\)')
code = sys.argv[0][(sys.argv[0].rfind('_') + 1):]
if not code:
sys.exit(1)
elif len(sys.argv) == 2 and sys.argv[1] == "autoconf":
print("yes")
elif len(sys.argv) == 2 and sys.argv[1] == "config":
print('graph_title Atmospheric pressure at code %s' % code)
print('graph_vlabel Pressure in hPa')
print('graph_category sensors')
print('pressure.label Pressure')
print('pressure.type GAUGE')
print('graph_args --base 1000 -l 850 -u 1050 --rigid')
print('graph_scale no')
else:
u = urlopen(url % code)
txt = str(u.read())
u.close()
hpa = re_hpa.findall(txt)[0]
print('pressure.value %s' % hpa)