cleanup and bug fixed

upload saved the key of the dict as int not str
This commit is contained in:
Anika 2024-03-20 13:28:19 +01:00
parent 4314f97ee3
commit 8d91c63a12
2 changed files with 7 additions and 18 deletions

3
app.py
View File

@ -128,8 +128,7 @@ def upload():
content = alarm["message"] content = alarm["message"]
global alarmIndex global alarmIndex
alarmIndex += 1 alarmIndex += 1
activeAlarms[alarmIndex] = {'datetime':datetime.strftime(time,"%d.%m.%Y %H:%M"),'message':content} activeAlarms[str(alarmIndex)] = {'datetime':datetime.strftime(time,"%d.%m.%Y %H:%M"),'message':content}
# ja, wir schreiben einfach das ganze File neu, ist aber einfacher # ja, wir schreiben einfach das ganze File neu, ist aber einfacher
with open('alarms.json', 'w') as f: with open('alarms.json', 'w') as f:
json.dump(activeAlarms, f, indent=2) json.dump(activeAlarms, f, indent=2)

View File

@ -67,28 +67,17 @@
method: "POST", method: "POST",
body: body, body: body,
}); });
fetch("/processAlarm", { reloadAlarms();
method: "GET"
}).then(response => {
return response.text();
})
.then(html => {
upcomingAlarms.innerHTML = html
})
fetch("/processpAlarm", {
method: "GET"
}).then(response => {
return response.text();
})
.then(html => {
previousAlarms.innerHTML = html
})
} }
async function deleteAlarm(id){ async function deleteAlarm(id){
const response = await fetch("http://127.0.0.1:5000/deletealarm", { const response = await fetch("http://127.0.0.1:5000/deletealarm", {
method: "POST", method: "POST",
body: id, body: id,
}); });
reloadAlarms();
}
function reloadAlarms(){
fetch("/processAlarm", { fetch("/processAlarm", {
method: "GET" method: "GET"
}).then(response => { }).then(response => {
@ -105,6 +94,7 @@
.then(html => { .then(html => {
previousAlarms.innerHTML = html previousAlarms.innerHTML = html
}) })
} }
function checkAlarms(){ function checkAlarms(){