root / plugins / weather / weather_press_ @ 417bebc3
Historique | Voir | Annoter | Télécharger (1,2 ko)
| 1 | a160dea0 | Maxim Kravets | #!/usr/bin/env python |
|---|---|---|---|
| 2 | 7e6774a0 | Ghirai | """ |
| 3 | 2d95020d | Samuel Smith | munin US NOAA weather plugin (http://tgftp.nws.noaa.gov) |
| 4 | 7e6774a0 | Ghirai | |
| 5 | Draws pressure in hPa. |
||
| 6 | Copy/link file as 'weather_pressure_CODE', like: weather_pressure_LOWW for Austria, Vienna. |
||
| 7 | |||
| 8 | 2d95020d | Samuel Smith | Get the code by going to http://tgftp.nws.noaa.gov, selecting your |
| 9 | 7e6774a0 | Ghirai | 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 | 2d95020d | Samuel Smith | url = 'http://tgftp.nws.noaa.gov/data/observations/metar/decoded/%s.TXT' |
| 20 | 7e6774a0 | Ghirai | |
| 21 | 417bebc3 | Lars Kruse | re_hpa = re.compile('Pressure.*\((\d+) hPa\)')
|
| 22 | 7e6774a0 | Ghirai | |
| 23 | |||
| 24 | code = sys.argv[0][(sys.argv[0].rfind('_')+1):]
|
||
| 25 | 417bebc3 | Lars Kruse | if not code: |
| 26 | sys.exit(1) |
||
| 27 | elif len(sys.argv) == 2 and sys.argv[1] == "autoconf": |
||
| 28 | print("yes")
|
||
| 29 | 7e6774a0 | Ghirai | elif len(sys.argv) == 2 and sys.argv[1] == "config": |
| 30 | 417bebc3 | Lars Kruse | print('graph_title Atmospheric pressure at code %s' % code)
|
| 31 | print('graph_vlabel Pressure in hPa')
|
||
| 32 | print('graph_category sensors')
|
||
| 33 | |||
| 34 | print('pressure.label Pressure')
|
||
| 35 | print('pressure.type GAUGE')
|
||
| 36 | print('graph_args --base 1000 -l 850 -u 1050 --rigid')
|
||
| 37 | print('graph_scale no')
|
||
| 38 | 7e6774a0 | Ghirai | else: |
| 39 | 417bebc3 | Lars Kruse | u = urllib.urlopen(url % code) |
| 40 | txt = u.read() |
||
| 41 | u.close() |
||
| 42 | 7e6774a0 | Ghirai | |
| 43 | 417bebc3 | Lars Kruse | hpa = re_hpa.findall(txt)[0] |
| 44 | print('pressure.value %s' % hpa) |
