let's ignore the bugs
This commit is contained in:
parent
08a85501ce
commit
0b2ff931b1
Binary file not shown.
20
alarms.json
20
alarms.json
|
@ -1,22 +1,10 @@
|
|||
[
|
||||
{
|
||||
"datetime": "12.03.2025 11:00",
|
||||
"message": "lj\u00f6sd"
|
||||
"datetime": "02.12.2024 18:00",
|
||||
"message": "Hallo"
|
||||
},
|
||||
{
|
||||
"datetime": "12.03.2025 11:00",
|
||||
"message": "lj\u00f6sd"
|
||||
},
|
||||
{
|
||||
"datetime": "11.02.2024 23:33",
|
||||
"message": ""
|
||||
},
|
||||
{
|
||||
"datetime": "12.03.2022 11:00",
|
||||
"message": "lj\u00f6sd"
|
||||
},
|
||||
{
|
||||
"datetime": "11.02.2024 23:23",
|
||||
"message": "lj\u00f6sd"
|
||||
"datetime": "12.02.2024 18:00",
|
||||
"message": "helpo"
|
||||
}
|
||||
]
|
|
@ -2,5 +2,9 @@
|
|||
{
|
||||
"datetime": "11.02.2024 22:58",
|
||||
"message": "Nice"
|
||||
},
|
||||
{
|
||||
"datetime": "12.02.2024 15:03",
|
||||
"message": "Lololol"
|
||||
}
|
||||
]
|
|
@ -12,7 +12,7 @@
|
|||
</head>
|
||||
<body>
|
||||
<nav class="navbar navbar-expand-md navbar-light bg-light">
|
||||
<a class="navbar-brand" href="{{ url_for('index')}}">FlaskBlog</a>
|
||||
<a class="navbar-brand" href="{{ url_for('index')}}">Zentrale</a>
|
||||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
||||
<span class="navbar-toggler-icon"></span>
|
||||
</button>
|
||||
|
@ -22,7 +22,7 @@
|
|||
<a class="nav-link" href="#">About</a>
|
||||
</li>
|
||||
<li class="nav-item">
|
||||
<a class="nav-link" href="{{url_for('create')}}">New Post</a>
|
||||
<a class="nav-link" href="{{url_for('refresh')}}">Reload</a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
{% extends 'base.html' %}
|
||||
|
||||
{% block content %}
|
||||
<h1>{% block title %} Create a New Post {% endblock %}</h1>
|
||||
|
||||
<form method="post">
|
||||
<div class="form-group">
|
||||
<label for="title">Title</label>
|
||||
<input type="text" name="title"
|
||||
placeholder="Post title" class="form-control"
|
||||
value="{{ request.form['title'] }}"></input>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label for="content">Content</label>
|
||||
<textarea name="content" placeholder="Post content"
|
||||
class="form-control">{{ request.form['content'] }}</textarea>
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<button type="submit" class="btn btn-primary">Submit</button>
|
||||
</div>
|
||||
</form>
|
||||
{% endblock %}
|
|
@ -11,7 +11,7 @@
|
|||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<div class="savedAlarms">
|
||||
<div class="savedAlarms" >
|
||||
<h3>Upcoming Alarms</h3>
|
||||
{% for alarm in alarms %}
|
||||
<div>
|
||||
|
@ -50,24 +50,40 @@
|
|||
|
||||
<div>
|
||||
<h3>Previous Alarm</h3>
|
||||
Script runs once for whatever reason????
|
||||
<script>
|
||||
async function getAlarms(){
|
||||
const response = await fetch("http://127.0.0.1:5000/alarms");
|
||||
const response = await fetch("http://127.0.0.1:5000/alarms", {method:"GET"});
|
||||
const alarms = await response.json();
|
||||
return 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,
|
||||
});
|
||||
}
|
||||
alarms = getAlarms();
|
||||
function checkAlarms(){
|
||||
console.log("hello")
|
||||
for(alarm in alarms){
|
||||
if(Date(alarm.datetime) <=new Date()){
|
||||
console.log("ALARM!");
|
||||
alert(alarm.message);
|
||||
// post alerting alarm
|
||||
alarms.then( (alarms) => {
|
||||
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 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);
|
||||
}
|
||||
setTimeout(checkAlarms, 15000);
|
||||
|
||||
)
|
||||
}
|
||||
checkAlarms();
|
||||
</script>
|
||||
|
|
25
test.py
25
test.py
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import subprocess
|
||||
from flask import request, Flask, render_template
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
@ -23,12 +24,9 @@ def preprocess():
|
|||
|
||||
@app.route("/", methods=('GET', 'POST'))
|
||||
def index():
|
||||
# preprocesing in andere Methode, alarm sortieren nach Zeitpunkt
|
||||
# alarm.txt alle alarme, alarm.json alle, die noch nicht behandelt wurden
|
||||
# alle alarme in alarme.json -> preprocessing wie in die Listen
|
||||
#alarms = open("alarms.txt").readlines()
|
||||
#logs = open("alarms.txt").readlines()
|
||||
preprocess()
|
||||
# reload sendet alle paramenter neu und die werden neu drangeflanscht
|
||||
if len(logs) <= 0:
|
||||
preprocess()
|
||||
|
||||
return render_template('index.html', logs = logs, alarms = activeAlarms, previousAlarms=previousAlarms)
|
||||
|
||||
|
@ -36,7 +34,6 @@ def index():
|
|||
def setAlarm():
|
||||
if request.method == 'POST':
|
||||
time = datetime.fromisoformat(request.form['datetime']).strftime("%d.%m.%Y %H:%M")
|
||||
print(time)
|
||||
content = request.form['alarmMessage']
|
||||
activeAlarms.append({'datetime':time,'message':content})
|
||||
|
||||
|
@ -70,9 +67,13 @@ def alarm():
|
|||
|
||||
if request.method == 'POST':
|
||||
print('ALARM')
|
||||
# gets alerting alarm, move to previous alarms and remove from active
|
||||
subprocess.call(['mpv','./alarm.mp3'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
||||
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)
|
||||
|
||||
|
||||
@app.route('/about')
|
||||
def create():
|
||||
return 'The about page'
|
||||
@app.route("/refresh")
|
||||
def refresh():
|
||||
return render_template('index.html', logs = logs, alarms = activeAlarms, previousAlarms=previousAlarms)
|
Loading…
Reference in New Issue