From 7991aebb692423a75cda8800ba61bd0283311a4d Mon Sep 17 00:00:00 2001 From: maik Date: Thu, 11 Jan 2024 22:05:30 +0100 Subject: [PATCH] first commit --- app.py | 58 ++++++++++++++++++++++++++++ templates/index.html | 85 +++++++++++++++++++++++++++++++++++++++++ templates/websites.json | 7 ++++ websites.json | 7 ++++ 4 files changed, 157 insertions(+) create mode 100644 app.py create mode 100644 templates/index.html create mode 100644 templates/websites.json create mode 100644 websites.json diff --git a/app.py b/app.py new file mode 100644 index 0000000..e451e88 --- /dev/null +++ b/app.py @@ -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) diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..d70fad9 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,85 @@ + + + + + + Digital Signage + + + + +
+ + +
+ + + + diff --git a/templates/websites.json b/templates/websites.json new file mode 100644 index 0000000..371ef02 --- /dev/null +++ b/templates/websites.json @@ -0,0 +1,7 @@ +{ + "websites": [ + "https://161hz.de", + "https://hs.matthes.me", + "https://cdn.161hz.de" + ] +} diff --git a/websites.json b/websites.json new file mode 100644 index 0000000..b647b99 --- /dev/null +++ b/websites.json @@ -0,0 +1,7 @@ +{ + "websites": [ + "https://161hz.de", + "https://161hz.stream", + "https://ontime.161hz.stream" + ] +}