From 5155b7d790e9d872a59de57b3b8cc7a31b8947f7 Mon Sep 17 00:00:00 2001 From: Justin Date: Mon, 24 Apr 2023 19:10:05 +0800 Subject: [PATCH] saveschedulersettings added --- server.py | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) diff --git a/server.py b/server.py index 1cfd717..32ff37d 100755 --- a/server.py +++ b/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__":