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