-
Notifications
You must be signed in to change notification settings - Fork 0
/
record.py
executable file
·58 lines (42 loc) · 1.34 KB
/
record.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import json
import syslog
import time
SOURCE = '/sys/devices/virtual/thermal/thermal_zone0/temp'
upper = 84000
lower = 0
def get_raw_temp():
with open(SOURCE, 'r') as f:
stuff = f.readlines()
t = int(''.join(stuff).strip())
return t
oparser = argparse.ArgumentParser(description="temperature logger")
oparser.add_argument("-v", dest="verbose",
default=False,
action="store_true",
help="verbose output")
oparser.add_argument("-n", dest="logging",
default=True,
action="store_false",
help="dry run: do not write to syslog")
oparser.add_argument("-c", dest="config_file",
required=True,
metavar="FILE",
help="JSON config file")
options = oparser.parse_args()
with open(options.config_file) as f:
config = json.load(f)
t0 = get_raw_temp()
time.sleep(1)
t1 = get_raw_temp()
tt = (t0 + t1) / 2000.0
summary = "OK" if tt < config['alert_temp'] else "ALERT"
message = 'zone0 temp %s %4.1f° [raw %i %i]' % (summary, tt, t0, t1)
if options.verbose:
print(message)
if options.logging:
syslog.openlog('zone0temp', syslog.LOG_PID)
syslog.syslog(message)
syslog.closelog()