2012-04-11 12:08:02 +02:00
|
|
|
#!/usr/bin/env python
|
2009-05-25 22:58:14 +02:00
|
|
|
"""
|
2016-08-29 19:23:25 +02:00
|
|
|
munin US NOAA weather plugin (http://tgftp.nws.noaa.gov)
|
2009-05-25 22:58:14 +02:00
|
|
|
|
|
|
|
Draws pressure in hPa.
|
|
|
|
Copy/link file as 'weather_pressure_CODE', like: weather_pressure_LOWW for Austria, Vienna.
|
|
|
|
|
2016-08-29 19:23:25 +02:00
|
|
|
Get the code by going to http://tgftp.nws.noaa.gov, selecting your
|
2009-05-25 22:58:14 +02:00
|
|
|
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
|
|
|
|
import urllib
|
|
|
|
import re
|
|
|
|
|
2016-08-29 19:23:25 +02:00
|
|
|
url = 'http://tgftp.nws.noaa.gov/data/observations/metar/decoded/%s.TXT'
|
2009-05-25 22:58:14 +02:00
|
|
|
|
2018-03-27 04:50:21 +02:00
|
|
|
re_hpa = re.compile('Pressure.*\((\d+) hPa\)')
|
2009-05-25 22:58:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
code = sys.argv[0][(sys.argv[0].rfind('_')+1):]
|
2018-03-27 04:50:21 +02:00
|
|
|
if not code:
|
|
|
|
sys.exit(1)
|
|
|
|
elif len(sys.argv) == 2 and sys.argv[1] == "autoconf":
|
|
|
|
print("yes")
|
2009-05-25 22:58:14 +02:00
|
|
|
elif len(sys.argv) == 2 and sys.argv[1] == "config":
|
2018-03-27 04:50:21 +02:00
|
|
|
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')
|
2009-05-25 22:58:14 +02:00
|
|
|
else:
|
2018-03-27 04:50:21 +02:00
|
|
|
u = urllib.urlopen(url % code)
|
|
|
|
txt = u.read()
|
|
|
|
u.close()
|
2009-05-25 22:58:14 +02:00
|
|
|
|
2018-03-27 04:50:21 +02:00
|
|
|
hpa = re_hpa.findall(txt)[0]
|
|
|
|
print('pressure.value %s' % hpa)
|