-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-temperature-recency
executable file
·41 lines (32 loc) · 1.33 KB
/
check-temperature-recency
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
#!/usr/bin/env python3
#
# Check that we have recently evaluated temperature.
#
# Configure using systemd user timer units https://gist.github.com/oprypin/0f0c3479ab53e00988b52919e5d7c144
#
import json
import sys
import os
from datetime import datetime
from datetime import date
import subprocess
import time
libdir = os.path.join(os.path.dirname(os.path.dirname(os.path.realpath(__file__))), 'lib')
if os.path.exists(libdir):
sys.path.append(libdir)
sys.path.append('/home/peter/.local/lib')
from PUStatusReporter import reporter
with open(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'volatile', 'config.json'), 'r') as config_file:
config = json.load(config_file)
# wait until we have confirmed network connectivity
while True:
process = subprocess.Popen(["ping", "-c", "1", config['ping_target']], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
output, error = process.communicate()
if process.returncode == 0:
break
else:
time.sleep(30)
status = reporter.get_status('cupboard_temperature', config['bearer_key'])
last_temp_check_date = datetime.strptime(status['payload'].split(' ')[1], '%Y-%m-%d')
if last_temp_check_date.date() < date.today():
subprocess.run([config['send_notification_script'], 'Cupboard Temperature is old', f'Cupboard Temperature last checked on {last_temp_check_date}'])