You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.7 KiB
58 lines
1.7 KiB
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)
|
|
|