root / plugins / other / weather_press_ @ 7e6774a0
Historique | Voir | Annoter | Télécharger (1,17 ko)
| 1 | 7e6774a0 | Ghirai | #!/usr/local/bin/python |
|---|---|---|---|
| 2 | """ |
||
| 3 | munin US NOAA weather plugin (http://weather.noaa.gov) |
||
| 4 | |||
| 5 | Draws pressure in hPa. |
||
| 6 | Copy/link file as 'weather_pressure_CODE', like: weather_pressure_LOWW for Austria, Vienna. |
||
| 7 | |||
| 8 | Get the code by going to http://weather.noaa.gov, selecting your |
||
| 9 | location, and copying the code from the address bar of your browser; should |
||
| 10 | be something like CODE.html. |
||
| 11 | |||
| 12 | Linux users might need to adjust the shebang. |
||
| 13 | """ |
||
| 14 | |||
| 15 | import sys |
||
| 16 | import urllib |
||
| 17 | import re |
||
| 18 | |||
| 19 | url = 'http://weather.noaa.gov/pub/data/observations/metar/decoded/%s.TXT' |
||
| 20 | |||
| 21 | re_hPa = re.compile('Pressure.*\((\d+) hPa\)')
|
||
| 22 | |||
| 23 | |||
| 24 | code = sys.argv[0][(sys.argv[0].rfind('_')+1):]
|
||
| 25 | if code == None: sys.exit(1) |
||
| 26 | |||
| 27 | if len(sys.argv) == 2 and sys.argv[1] == "autoconf": |
||
| 28 | |||
| 29 | print "yes" |
||
| 30 | |||
| 31 | elif len(sys.argv) == 2 and sys.argv[1] == "config": |
||
| 32 | |||
| 33 | print 'graph_title Atmospheric pressure at code %s' % code |
||
| 34 | print 'graph_vlabel Pressure in hPa' |
||
| 35 | print 'graph_category Weather' |
||
| 36 | |||
| 37 | print 'pressure.label Pressure' |
||
| 38 | print 'pressure.type GAUGE' |
||
| 39 | print 'graph_args --base 1000 -l 850 -u 1050 --rigid' |
||
| 40 | print 'graph_scale no' |
||
| 41 | |||
| 42 | else: |
||
| 43 | |||
| 44 | u = urllib.urlopen(url % code) |
||
| 45 | txt = u.read() |
||
| 46 | u.close() |
||
| 47 | |||
| 48 | hPa = re_hPa.findall(txt)[0] |
||
| 49 | |||
| 50 | print 'pressure.value %s' % hPa |
