saveschedulersettings added
This commit is contained in:
parent
884ff6b5fa
commit
5155b7d790
41
server.py
41
server.py
@ -1161,10 +1161,49 @@ def shutdown():
|
||||
os.system("sudo shutdown now")
|
||||
return index()
|
||||
|
||||
|
||||
@app.route("/saveSchedulerSettings", methods = ['PUT', 'POST'])
|
||||
def saveSchedulerSettings():
|
||||
|
||||
|
||||
data= request.data.decode('utf-8')
|
||||
input_settings = json.loads(data)
|
||||
|
||||
initialize_json = '{"shutdown": {"hour": "00", "minute": "00", "enabled": false}, "reboot":{"hour": "00", "minute": "00", "enabled": false}, "timezone": "GMT"}'
|
||||
|
||||
if 'scheduler.json' not in os.listdir('csv/'):
|
||||
with open('csv/scheduler.json', 'w') as f:
|
||||
f.write(initialize_json)
|
||||
|
||||
try:
|
||||
with open('csv/scheduler.json','r') as f:
|
||||
scheduler_settings = json.load(f)
|
||||
except:
|
||||
scheduler_settings = {"shutdown": {"hour": "00", "minute": "00", "enabled": False}, "reboot":{"hour": "00", "minute": "00", "enabled": False}, "timezone": "GMT"}
|
||||
|
||||
scheduler_settings['shutdown']['hour'] = input_settings['shutdown_hour']
|
||||
scheduler_settings['shutdown']['minute'] = input_settings['shutdown_minute']
|
||||
scheduler_settings['shutdown']['enabled'] = input_settings['shutdown_enabled']
|
||||
|
||||
scheduler_settings['reboot']['hour'] = input_settings['reboot_hour']
|
||||
scheduler_settings['reboot']['minute'] = input_settings['reboot_minute']
|
||||
scheduler_settings['reboot']['enabled'] = input_settings['reboot_enabled']
|
||||
|
||||
scheduler_settings['timezone'] = input_settings['timezone']
|
||||
|
||||
with open('csv/scheduler.json', 'w') as f:
|
||||
json.dump(scheduler_settings,f)
|
||||
|
||||
f = open('csv/last_updates.json', 'r')
|
||||
last_updates = json.load(f)
|
||||
f.close()
|
||||
|
||||
last_updates['scheduler']['force'] = True
|
||||
|
||||
f = open('csv/last_updates.json', 'w')
|
||||
json.dump(last_updates, f)
|
||||
f.close()
|
||||
|
||||
return index()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
Loading…
Reference in New Issue
Block a user