saveschedulersettings added

This commit is contained in:
Justin 2023-04-24 19:10:05 +08:00 committed by GitHub
parent 884ff6b5fa
commit 5155b7d790
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1162,9 +1162,48 @@ def shutdown():
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__":