#!/usr/bin/python3 import os import requests import json import subprocess import time script_directory = os.path.dirname(os.path.realpath(__file__)) with open(script_directory + '/../config/config.json', 'r') as thefile: config = json.load(thefile) auth = config['auth'] urls = config['urls'] control = config['control'] try: ro = requests.get(urls['override'], auth=(auth['user'], auth['pass'])) except: print("Error getting override. Defaulting to off.") override = False else: override = ro.json() try: rs = requests.get(urls['schedule'], auth=(auth['user'], auth['pass'])) except: print("Error getting schedule from webservice. Defaulting to off.") schedule = False else: schedule = rs.json() if schedule: demand = schedule else: demand = False if override is not None: demand = override runs = 0 if demand: while runs < 3: subprocess.run([script_directory + '/../sender/rf', control['on']['code'], control['on']['multiplier'], control['on']['inverse']]) with open(script_directory + '/../rwdata/state.txt', 'w+') as thefile: thefile.write("1") time.sleep(1) runs = runs + 1 else: while runs < 3: subprocess.run([script_directory + '/../sender/rf', control['off']['code'], control['off']['multiplier'], control['off']['inverse']]) with open(script_directory + '/../rwdata/state.txt', 'w+') as thefile: thefile.write("0") time.sleep(1) runs = runs + 1