multiprocessing for scheduler
This commit is contained in:
parent
dbfb14704b
commit
26383efcac
94
server.py
94
server.py
@ -1232,6 +1232,100 @@ def saveSchedulerSettings():
|
|||||||
return index()
|
return index()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def scheduled_brightness():
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
f = open('csv/scheduler.json','r')
|
||||||
|
schedules = json.load(f)
|
||||||
|
f.close()
|
||||||
|
except:
|
||||||
|
schedules = {"shutdown": {"hour": "00", "minute": "00", "enabled": False}, "reboot":{"hour": "00", "minute": "00", "enabled": False}, "timezone": "GMT", "brightness1":{"hour": "00", "minute": "00", "bright": "10", "enabled": False}, "brightness2":{"hour": "00", "minute": "00", "bright": "10", "enabled": False}, "brightness3":{"hour": "00", "minute": "00", "bright": "10", "enabled": False}, "brightness4":{"hour": "00", "minute": "00", "bright": "10", "enabled": False}}
|
||||||
|
|
||||||
|
timezone_brightness = schedules['timezone']
|
||||||
|
|
||||||
|
brightness1_hour = schedules['brightness1']['hour']
|
||||||
|
brightness1_minute = schedules['brightness1']['minute']
|
||||||
|
brightness1_bright = schedules['brightness1']['bright']
|
||||||
|
brightness1_enabled = schedules['brightness1']['enabled']
|
||||||
|
|
||||||
|
brightness2_hour = schedules['brightness2']['hour']
|
||||||
|
brightness2_minute = schedules['brightness2']['minute']
|
||||||
|
brightness2_bright = schedules['brightness2']['bright']
|
||||||
|
brightness2_enabled = schedules['brightness2']['enabled']
|
||||||
|
|
||||||
|
brightness3_hour = schedules['brightness3']['hour']
|
||||||
|
brightness3_minute = schedules['brightness3']['minute']
|
||||||
|
brightness3_bright = schedules['brightness3']['bright']
|
||||||
|
brightness3_enabled = schedules['brightness3']['enabled']
|
||||||
|
|
||||||
|
brightness4_hour = schedules['brightness4']['hour']
|
||||||
|
brightness4_minute = schedules['brightness4']['minute']
|
||||||
|
brightness4_bright = schedules['brightness4']['bright']
|
||||||
|
brightness4_enabled = schedules['brightness4']['enabled']
|
||||||
|
|
||||||
|
try:
|
||||||
|
if brightness1_enabled and datetime.datetime.now(pytz.timezone(timezone_brightness)).strftime("%H:%M") == brightness1_hour+':'+brightness1_minute:
|
||||||
|
brightness = max(min(int(brightness1_bright), 10), 1)
|
||||||
|
ticker.sendline(str(brightness-1))
|
||||||
|
f = open('csv/general_settings.json', 'r')
|
||||||
|
general_settings = json.load(f)
|
||||||
|
f.close()
|
||||||
|
general_settings['brightness'] = int(brightness)
|
||||||
|
f = open('csv/general_settings.json', 'w')
|
||||||
|
json.dump(general_settings, f)
|
||||||
|
f.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
if brightness2_enabled and datetime.datetime.now(pytz.timezone(timezone_brightness)).strftime("%H:%M") == brightness2_hour+':'+brightness2_minute:
|
||||||
|
brightness = max(min(int(brightness2_bright), 10), 1)
|
||||||
|
ticker.sendline(str(brightness-1))
|
||||||
|
f = open('csv/general_settings.json', 'r')
|
||||||
|
general_settings = json.load(f)
|
||||||
|
f.close()
|
||||||
|
general_settings['brightness'] = int(brightness)
|
||||||
|
f = open('csv/general_settings.json', 'w')
|
||||||
|
json.dump(general_settings, f)
|
||||||
|
f.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
if brightness3_enabled and datetime.datetime.now(pytz.timezone(timezone_brightness)).strftime("%H:%M") == brightness3_hour+':'+brightness3_minute:
|
||||||
|
brightness = max(min(int(brightness3_bright), 10), 1)
|
||||||
|
ticker.sendline(str(brightness-1))
|
||||||
|
f = open('csv/general_settings.json', 'r')
|
||||||
|
general_settings = json.load(f)
|
||||||
|
f.close()
|
||||||
|
general_settings['brightness'] = int(brightness)
|
||||||
|
f = open('csv/general_settings.json', 'w')
|
||||||
|
json.dump(general_settings, f)
|
||||||
|
f.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
if brightness4_enabled and datetime.datetime.now(pytz.timezone(timezone_brightness)).strftime("%H:%M") == brightness4_hour+':'+brightness4_minute:
|
||||||
|
brightness = max(min(int(brightness4_bright), 10), 1)
|
||||||
|
ticker.sendline(str(brightness-1))
|
||||||
|
f = open('csv/general_settings.json', 'r')
|
||||||
|
general_settings = json.load(f)
|
||||||
|
f.close()
|
||||||
|
general_settings['brightness'] = int(brightness)
|
||||||
|
f = open('csv/general_settings.json', 'w')
|
||||||
|
json.dump(general_settings, f)
|
||||||
|
f.close()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
time.sleep(20)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
scheduled_b = Process(target=scheduled_brightness)
|
||||||
|
scheduled_b.start()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
||||||
app.run(host='0.0.0.0', port=1024, debug=False) # the debuggger causes flickering
|
app.run(host='0.0.0.0', port=1024, debug=False) # the debuggger causes flickering
|
||||||
|
Loading…
Reference in New Issue
Block a user