closes #1,#3
This commit is contained in:
parent
0b2ff931b1
commit
ed8fc409f8
Binary file not shown.
12
alarms.json
12
alarms.json
|
@ -1,10 +1,14 @@
|
|||
[
|
||||
{
|
||||
"datetime": "02.12.2024 18:00",
|
||||
"message": "Hallo"
|
||||
"datetime": "05.04.2025 06:33",
|
||||
"message": "Test"
|
||||
},
|
||||
{
|
||||
"datetime": "12.02.2024 18:00",
|
||||
"message": "helpo"
|
||||
"datetime": "05.04.2025 06:57",
|
||||
"message": "EEh"
|
||||
},
|
||||
{
|
||||
"datetime": "04.03.2024 18:40",
|
||||
"message": "PREVIOUS"
|
||||
}
|
||||
]
|
12
logs.json
12
logs.json
|
@ -6,5 +6,17 @@
|
|||
{
|
||||
"datetime": "12.02.2024 15:03",
|
||||
"message": "Lololol"
|
||||
},
|
||||
{
|
||||
"datetime": "22.02.2024 11:14",
|
||||
"message": "Seitenschneider an Leon"
|
||||
},
|
||||
{
|
||||
"datetime": "04.03.2024 13:02",
|
||||
"message": "hkjaflksaflksafl kisafjdbsafdo\u00f6ijar\u00f6oirpijwfeij"
|
||||
},
|
||||
{
|
||||
"datetime": "04.03.2024 18:02",
|
||||
"message": "hdhdh"
|
||||
}
|
||||
]
|
|
@ -0,0 +1,6 @@
|
|||
<h3>Upcoming Alarms</h3>
|
||||
{% for alarm in alarms %}
|
||||
<div>
|
||||
{{ alarm.datetime }}: {{ alarm.message }}
|
||||
</div>
|
||||
{% endfor %}
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
{% block content %}
|
||||
<h1>{% block title %} Partey! {% endblock %}</h1>
|
||||
<meta id="my-data" data-alarms="{{alarms}}" data-logs="{{logs}}">
|
||||
<div class="grid-container">
|
||||
<div class="savedLogs">
|
||||
<h3>Logs</h3>
|
||||
|
@ -11,7 +12,7 @@
|
|||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="savedAlarms" >
|
||||
<div class="savedAlarms" id="upcomingAlarms">
|
||||
<h3>Upcoming Alarms</h3>
|
||||
{% for alarm in alarms %}
|
||||
<div>
|
||||
|
@ -48,44 +49,53 @@
|
|||
</form>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div class="previousAlarms" id="previousAlarms">
|
||||
<h3>Previous Alarm</h3>
|
||||
<script>
|
||||
async function getAlarms(){
|
||||
const response = await fetch("http://127.0.0.1:5000/alarms", {method:"GET"});
|
||||
const alarms = await response.json();
|
||||
return alarms
|
||||
}
|
||||
alarms = {{ alarms|tojson }};
|
||||
console.log(alarms);
|
||||
async function postAlarm(alarm){
|
||||
var body = JSON.stringify(alarm)
|
||||
const response = await fetch("http://127.0.0.1:5000/alarms", {
|
||||
method: "POST",
|
||||
body: body,
|
||||
});
|
||||
fetch("/processAlarm", {
|
||||
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
|
||||
})
|
||||
}
|
||||
alarms = getAlarms();
|
||||
function checkAlarms(){
|
||||
alarms.then( (alarms) => {
|
||||
for(var i = 0; i < alarms.length; i++){
|
||||
|
||||
const [dateComponents, timeComponents] = alarms[i].datetime.split(' ');
|
||||
for(var i = 0; i < alarms.length; i++){
|
||||
|
||||
const [dateComponents, timeComponents] = alarms[i].datetime.split(' ');
|
||||
|
||||
const [day, month, year] = dateComponents.split('.');
|
||||
const [hours, minutes] = timeComponents.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()){
|
||||
console.log("ALARM!");
|
||||
postAlarm(alarms[i]);
|
||||
alert(alarms[i].message);
|
||||
}
|
||||
}
|
||||
setTimeout(checkAlarms, 15000);
|
||||
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);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
)
|
||||
setTimeout(checkAlarms, 15000);
|
||||
}
|
||||
checkAlarms();
|
||||
checkAlarms();
|
||||
</script>
|
||||
{% for alarm in previousAlarms %}
|
||||
<div>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<label id="value_lable">
|
||||
{% for log in logs %}
|
||||
{{ log }}<br>
|
||||
{% endfor %}
|
||||
</label>
|
|
@ -0,0 +1,6 @@
|
|||
<h3>Previous Alarms</h3>
|
||||
{% for alarm in previousAlarms %}
|
||||
<div>
|
||||
{{ alarm.datetime }}: {{ alarm.message }}
|
||||
</div>
|
||||
{% endfor %}
|
18
test.py
18
test.py
|
@ -1,6 +1,6 @@
|
|||
import json
|
||||
import subprocess
|
||||
from flask import request, Flask, render_template
|
||||
from flask import redirect, request, Flask, render_template, url_for
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
||||
|
@ -43,8 +43,7 @@ def setAlarm():
|
|||
|
||||
# Closing file
|
||||
f.close()
|
||||
|
||||
return render_template('index.html', logs = logs, alarms = activeAlarms, previousAlarms=previousAlarms)
|
||||
return redirect(url_for('index'))
|
||||
|
||||
@app.route('/sendLog', methods=('GET', 'POST'))
|
||||
def sendLog():
|
||||
|
@ -58,7 +57,7 @@ def sendLog():
|
|||
# Closing file
|
||||
f.close()
|
||||
|
||||
return render_template('index.html', logs = logs, alarms = activeAlarms, previousAlarms=previousAlarms)
|
||||
return redirect(url_for('index'))
|
||||
|
||||
@app.route('/alarms', methods=('GET','POST'))
|
||||
def alarm():
|
||||
|
@ -71,8 +70,15 @@ def alarm():
|
|||
data = json.loads(request.data.decode('UTF-8'))
|
||||
previousAlarms.append(data)
|
||||
activeAlarms.remove(data)
|
||||
# render_template übergibt argumente komisch -> force reload
|
||||
return render_template('index.html', logs = logs, alarms = activeAlarms, previousAlarms=previousAlarms)
|
||||
return redirect(url_for('index'))
|
||||
|
||||
@app.route('/processAlarm')
|
||||
def processAlarm():
|
||||
return render_template('alarms.html', alarms=activeAlarms)
|
||||
|
||||
@app.route('/processpAlarm')
|
||||
def processpAlarm():
|
||||
return render_template('palarms.html', previousAlarms=previousAlarms)
|
||||
|
||||
@app.route("/refresh")
|
||||
def refresh():
|
||||
|
|
Loading…
Reference in New Issue