first commit

main
maik 2 years ago
parent 1de944fa36
commit 7991aebb69
  1. 58
      app.py
  2. 85
      templates/index.html
  3. 7
      templates/websites.json
  4. 7
      websites.json

@ -0,0 +1,58 @@
import json
import os
from flask import Flask, render_template
from apscheduler.schedulers.background import BackgroundScheduler
from threading import Thread # Importiere die Thread-Klasse
app = Flask(__name__)
json_file_path = 'websites.json'
websites = []
def load_websites():
try:
with open(json_file_path, 'r') as json_file:
websites_data = json.load(json_file)
return websites_data.get('websites', [])
except FileNotFoundError:
print("Die Datei 'websites.json' wurde nicht gefunden.")
return []
def has_file_changed():
try:
current_mtime = os.path.getmtime(json_file_path)
return current_mtime != has_file_changed.last_mtime
except FileNotFoundError:
return False
has_file_changed.last_mtime = 0
def update_websites():
global websites
if has_file_changed():
print("Die Datei 'websites.json' wurde geändert. Aktualisiere die Websites.")
websites = load_websites()
has_file_changed.last_mtime = os.path.getmtime(json_file_path)
@app.route('/')
def index():
update_websites()
if websites:
return render_template('index.html', current_website=websites[0], websites=websites)
else:
return "Keine Websites verfügbar."
def periodic_update():
print("Periodisches Update alle 10 Sekunden.")
update_websites()
if __name__ == '__main__':
scheduler = BackgroundScheduler()
scheduler.add_job(func=periodic_update, trigger="interval", seconds=10)
# Erstelle einen Thread für den Scheduler und starte ihn
scheduler_thread = Thread(target=scheduler.start)
scheduler_thread.start()
# Starte die Flask-Anwendung
app.run(debug=False)

@ -0,0 +1,85 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Digital Signage</title>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<style>
body {
margin: 0;
padding: 0;
font-family: Arial, sans-serif;
}
#websiteFrame {
width: 100%;
height: 100vh;
border: 0;
}
#container {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100vh;
}
#navigation {
display: flex;
margin-top: 10px;
}
#prevBtn, #nextBtn {
margin: 0 10px;
padding: 8px 16px;
font-size: 14px;
}
@media (max-width: 600px) {
#navigation {
flex-direction: column;
}
#prevBtn, #nextBtn {
margin: 5px 0;
}
}
</style>
</head>
<body>
<div id="container">
<iframe id="websiteFrame" src="{{ current_website }}" frameborder="0"></iframe>
<!-- <div id="navigation">
<button id="prevBtn">Vorherige Seite</button>
<button id="nextBtn">Nächste Seite</button>
</div> -->
</div>
<script>
var websites = {{ websites|tojson|safe }};
var currentIndex = 0;
function updateWebsite() {
$("#websiteFrame").attr("src", websites[currentIndex]);
}
$("#prevBtn").click(function() {
currentIndex = (currentIndex - 1 + websites.length) % websites.length;
updateWebsite();
});
$("#nextBtn").click(function() {
currentIndex = (currentIndex + 1) % websites.length;
updateWebsite();
});
// Starte den Wechselprozess alle 10 Sekunden
setInterval(function() {
currentIndex = (currentIndex + 1) % websites.length;
updateWebsite();
}, 10000);
</script>
</body>
</html>

@ -0,0 +1,7 @@
{
"websites": [
"https://161hz.de",
"https://hs.matthes.me",
"https://cdn.161hz.de"
]
}

@ -0,0 +1,7 @@
{
"websites": [
"https://161hz.de",
"https://161hz.stream",
"https://ontime.161hz.stream"
]
}
Loading…
Cancel
Save