Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / weather / weather_temp_ @ 7063330e

Historique | Voir | Annoter | Télécharger (1,32 ko)

1
#!/usr/bin/env python
2
"""
3
munin US NOAA weather plugin (http://tgftp.nws.noaa.gov)
4

    
5
Draws temperature/dew point in C.
6
Copy/link file as 'weather_temp_CODE', like: weather_temp_LOWW for Austria, Vienna.
7

    
8
Get the code by going to http://tgftp.nws.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://tgftp.nws.noaa.gov/data/observations/metar/decoded/%s.TXT'
20

    
21
re_C = re.compile(r'Temperature:.*\((-?\d+\.?\d?) C\)')
22
re_DewC = re.compile(r'Dew.*\((-?\d+\.?\d?) C\)')
23

    
24
code = sys.argv[0][(sys.argv[0].rfind('_') + 1):]
25

    
26

    
27
if not code:
28
    sys.exit(1)
29
elif len(sys.argv) == 2 and sys.argv[1] == "autoconf":
30
    print("yes")
31
elif len(sys.argv) == 2 and sys.argv[1] == "config":
32
    print('graph_title Temperature and Dew Point at code %s' % code)
33
    print('graph_vlabel Temperature and Dew Point in C')
34
    print('graph_category sensors')
35
    print('temperature.label Temperature')
36
    print('dewpoint.label Dew Point')
37
    print('graph_args --base 1000 -l 0')
38
else:
39
    u = urllib.urlopen(url % code)
40
    txt = u.read()
41
    u.close()
42

    
43
    C = re_C.findall(txt)[0]
44
    DewC = re_DewC.findall(txt)[0]
45
    print('temperature.value %s' % C)
46
    print('dewpoint.value %s' % DewC)