fixed alarms, dicts sind doof
This commit is contained in:
parent
5e3a3a8272
commit
07b786c7a2
13
app.py
13
app.py
|
@ -61,8 +61,6 @@ def index():
|
|||
sorted_prevAlarms = dict(sorted(previousAlarms.items(), key=lambda x:x[1]['datetime']))
|
||||
|
||||
|
||||
print(sorted_alarms)
|
||||
|
||||
return render_template('index.html', logs = logs, alarms = sorted_alarms, previousAlarms=sorted_prevAlarms)
|
||||
|
||||
@app.route('/setAlarm', methods=('GET', 'POST'))
|
||||
|
@ -122,9 +120,11 @@ def alarm():
|
|||
if request.method == 'POST':
|
||||
print('ALARM')
|
||||
subprocess.call(['mpv','./alarm.mp3'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
data = json.loads(request.data.decode('UTF-8'))
|
||||
previousAlarms[data] = activeAlarms[data]
|
||||
activeAlarms.pop(data)
|
||||
id = request.data.decode('UTF-8')
|
||||
alarm = activeAlarms[id]
|
||||
previousAlarms[id] = alarm
|
||||
activeAlarms.pop(id)
|
||||
# what about Todos?
|
||||
return redirect(url_for('index'))
|
||||
|
||||
@app.route('/deletealarm', methods=('GET','POST'))
|
||||
|
@ -144,11 +144,12 @@ def deleteAlarm():
|
|||
def checktodo():
|
||||
if request.method == 'POST':
|
||||
id = request.data.decode('UTF-8')
|
||||
current_state = todos_dict[id]['done']
|
||||
todos_dict[id] = {'done': not todos_dict[id]['done'], 'message': todos_dict[id]['message']}
|
||||
if id in activeAlarms:
|
||||
previousAlarms[id] = activeAlarms[id]
|
||||
activeAlarms.pop(id)
|
||||
elif id in previousAlarms:
|
||||
elif id in previousAlarms and not current_state:
|
||||
activeAlarms[id] = previousAlarms[id]
|
||||
previousAlarms.pop(id)
|
||||
with open('todos.json', 'w') as f:
|
||||
|
|
|
@ -61,10 +61,9 @@
|
|||
<script>
|
||||
alarms = {{ alarms|tojson }};
|
||||
async function postAlarm(alarm){
|
||||
var body = JSON.stringify(alarm)
|
||||
const response = await fetch("http://127.0.0.1:5000/alarms", {
|
||||
method: "POST",
|
||||
body: body,
|
||||
body: alarm,
|
||||
});
|
||||
reloadAlarms();
|
||||
}
|
||||
|
@ -97,19 +96,17 @@
|
|||
}
|
||||
|
||||
function checkAlarms(){
|
||||
for(var i = 0; i < alarms.length; i++){
|
||||
|
||||
const [dateComponents, timeComponents] = alarms[i].datetime.split(' ');
|
||||
for(var alarmIdx in alarms){
|
||||
const [dateComponents, timeComponents] = alarms[alarmIdx]['datetime'].split(' ');
|
||||
|
||||
const [day, month, year] = dateComponents.split('.');
|
||||
const [hours, minutes] = timeComponents.split(':');
|
||||
|
||||
const date = new Date(+year, +month - 1, +day, +hours, +minutes);
|
||||
if(date <=new Date()){
|
||||
postAlarm(alarms[i]);
|
||||
alert(alarms[i].message);
|
||||
alarms.splice(i, 1);
|
||||
|
||||
postAlarm(alarmIdx);
|
||||
alert(alarms[alarmIdx].message);
|
||||
delete alarms[alarmIdx];
|
||||
}
|
||||
}
|
||||
setTimeout(checkAlarms, 15000);
|
||||
|
|
|
@ -42,23 +42,27 @@
|
|||
// check alarms in here too
|
||||
alarms = {{ alarms|tojson }};
|
||||
function checkAlarms(){
|
||||
for(var i = 0; i < alarms.length; i++){
|
||||
|
||||
const [dateComponents, timeComponents] = alarms[i].datetime.split(' ');
|
||||
for(var alarmIdx in alarms){
|
||||
const [dateComponents, timeComponents] = alarms[alarmIdx]['datetime'].split(' ');
|
||||
|
||||
const [day, month, year] = dateComponents.split('.');
|
||||
const [hours, minutes] = timeComponents.split(':');
|
||||
|
||||
const date = new Date(+year, +month - 1, +day, +hours, +minutes);
|
||||
if(date <=new Date()){
|
||||
postAlarm(alarms[i]);
|
||||
alert(alarms[i].message);
|
||||
alarms.splice(i, 1);
|
||||
|
||||
postAlarm(alarmIdx);
|
||||
alert(alarms[alarmIdx].message);
|
||||
delete alarms[alarmIdx];
|
||||
}
|
||||
}
|
||||
setTimeout(checkAlarms, 15000);
|
||||
}
|
||||
async function postAlarm(alarm){
|
||||
const response = await fetch("http://127.0.0.1:5000/alarms", {
|
||||
method: "POST",
|
||||
body: alarm,
|
||||
});
|
||||
}
|
||||
checkAlarms();
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Reference in New Issue