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",
|
"datetime": "05.04.2025 06:33",
|
||||||
"message": "Hallo"
|
"message": "Test"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"datetime": "12.02.2024 18:00",
|
"datetime": "05.04.2025 06:57",
|
||||||
"message": "helpo"
|
"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",
|
"datetime": "12.02.2024 15:03",
|
||||||
"message": "Lololol"
|
"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 %}
|
{% block content %}
|
||||||
<h1>{% block title %} Partey! {% endblock %}</h1>
|
<h1>{% block title %} Partey! {% endblock %}</h1>
|
||||||
|
<meta id="my-data" data-alarms="{{alarms}}" data-logs="{{logs}}">
|
||||||
<div class="grid-container">
|
<div class="grid-container">
|
||||||
<div class="savedLogs">
|
<div class="savedLogs">
|
||||||
<h3>Logs</h3>
|
<h3>Logs</h3>
|
||||||
|
@ -11,7 +12,7 @@
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
<div class="savedAlarms" >
|
<div class="savedAlarms" id="upcomingAlarms">
|
||||||
<h3>Upcoming Alarms</h3>
|
<h3>Upcoming Alarms</h3>
|
||||||
{% for alarm in alarms %}
|
{% for alarm in alarms %}
|
||||||
<div>
|
<div>
|
||||||
|
@ -48,44 +49,53 @@
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div class="previousAlarms" id="previousAlarms">
|
||||||
<h3>Previous Alarm</h3>
|
<h3>Previous Alarm</h3>
|
||||||
<script>
|
<script>
|
||||||
async function getAlarms(){
|
alarms = {{ alarms|tojson }};
|
||||||
const response = await fetch("http://127.0.0.1:5000/alarms", {method:"GET"});
|
console.log(alarms);
|
||||||
const alarms = await response.json();
|
|
||||||
return alarms
|
|
||||||
}
|
|
||||||
async function postAlarm(alarm){
|
async function postAlarm(alarm){
|
||||||
var body = JSON.stringify(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: 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(){
|
function checkAlarms(){
|
||||||
alarms.then( (alarms) => {
|
for(var i = 0; i < alarms.length; i++){
|
||||||
for(var i = 0; i < alarms.length; i++){
|
|
||||||
|
const [dateComponents, timeComponents] = alarms[i].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()){
|
||||||
console.log("ALARM!");
|
postAlarm(alarms[i]);
|
||||||
postAlarm(alarms[i]);
|
alert(alarms[i].message);
|
||||||
alert(alarms[i].message);
|
alarms.splice(i, 1);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
setTimeout(checkAlarms, 15000);
|
|
||||||
}
|
}
|
||||||
|
setTimeout(checkAlarms, 15000);
|
||||||
)
|
|
||||||
}
|
}
|
||||||
checkAlarms();
|
checkAlarms();
|
||||||
</script>
|
</script>
|
||||||
{% for alarm in previousAlarms %}
|
{% for alarm in previousAlarms %}
|
||||||
<div>
|
<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 json
|
||||||
import subprocess
|
import subprocess
|
||||||
from flask import request, Flask, render_template
|
from flask import redirect, request, Flask, render_template, url_for
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
|
|
||||||
|
@ -43,8 +43,7 @@ def setAlarm():
|
||||||
|
|
||||||
# Closing file
|
# Closing file
|
||||||
f.close()
|
f.close()
|
||||||
|
return redirect(url_for('index'))
|
||||||
return render_template('index.html', logs = logs, alarms = activeAlarms, previousAlarms=previousAlarms)
|
|
||||||
|
|
||||||
@app.route('/sendLog', methods=('GET', 'POST'))
|
@app.route('/sendLog', methods=('GET', 'POST'))
|
||||||
def sendLog():
|
def sendLog():
|
||||||
|
@ -58,7 +57,7 @@ def sendLog():
|
||||||
# Closing file
|
# Closing file
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
return render_template('index.html', logs = logs, alarms = activeAlarms, previousAlarms=previousAlarms)
|
return redirect(url_for('index'))
|
||||||
|
|
||||||
@app.route('/alarms', methods=('GET','POST'))
|
@app.route('/alarms', methods=('GET','POST'))
|
||||||
def alarm():
|
def alarm():
|
||||||
|
@ -71,8 +70,15 @@ def alarm():
|
||||||
data = json.loads(request.data.decode('UTF-8'))
|
data = json.loads(request.data.decode('UTF-8'))
|
||||||
previousAlarms.append(data)
|
previousAlarms.append(data)
|
||||||
activeAlarms.remove(data)
|
activeAlarms.remove(data)
|
||||||
# render_template übergibt argumente komisch -> force reload
|
return redirect(url_for('index'))
|
||||||
return render_template('index.html', logs = logs, alarms = activeAlarms, previousAlarms=previousAlarms)
|
|
||||||
|
@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")
|
@app.route("/refresh")
|
||||||
def refresh():
|
def refresh():
|
||||||
|
|
Loading…
Reference in New Issue