From 3e73280e7a4b72757b895c39ff97ea25136f593c Mon Sep 17 00:00:00 2001 From: Norbert Jovari Date: Sat, 12 Apr 2025 20:49:48 +0200 Subject: [PATCH] auto reload at file change --- README.en.md | 5 ++--- README.md | 5 ++--- main.py | 36 +++++++++++++++++++++++------------- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/README.en.md b/README.en.md index 3d5bd01..fe02056 100644 --- a/README.en.md +++ b/README.en.md @@ -9,7 +9,7 @@ Use it to display the results on a TV or to serve results for the competitors. - + @@ -25,7 +25,6 @@ The following variables can be found at the top of the `main.py` script: - `scroll_interval`: Time interval (in seconds) between each scroll - `bottom_wait_time`: Time to wait (in seconds) at the bottom of the page before reloading - `top_wait_time`: Time to wait (in seconds) at the top of the page before starting to scroll -- `reload_interval`: Time interval (in seconds) to reload the page if no scrolling is needed. Set this value minimum 1 seconds larger than the export interval in OE ## Getting Started @@ -80,4 +79,4 @@ This project is licensed under the MIT License - see the `LICENSE` file for deta
-

Made with ❤️ on 603 NYÍRSÉG IC

\ No newline at end of file +

Made with ❤️ and ☕ on 603 NYÍRSÉG IC

\ No newline at end of file diff --git a/README.md b/README.md index 0a84672..3fc3522 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ Egyszerű python program, amivel a tájfutó eseményeken használt OE11 és OE1 - + @@ -25,7 +25,6 @@ A `main.py` fájl elején található, szerkeszthető változók: - `scroll_interval`: Időtartam másodpercben, ennyi időnként görget - `bottom_wait_time`: Időtartam másodpercben, ennyit vár ha a lap aljára ért újratöltés előtt - `top_wait_time`: Időtartam másodpercben, ennyit vár a lap tetején, mielőtt elkezdődne a görgetés -- `reload_interval`: Időtartam másodpercben, ennyit vár újratöltés előtt, ha nincs szükség görgetésre, mert a tartalom kifér a képernyőre. Legyen ez az érték minimum 1 másodperccel több, mint az automatikus exportálás ideje az OE-ben. ## Használat @@ -80,4 +79,4 @@ Ez a projekt az MIT Licensz alatt van licenszelve - részletekért lásd a LICEN
-

Készült sok ❤️-el a 603 NYÍRSÉG IC-n

\ No newline at end of file +

Készült sok ❤️-el és ☕-val a 603 NYÍRSÉG IC-n

\ No newline at end of file diff --git a/main.py b/main.py index be75d3e..517e3b3 100644 --- a/main.py +++ b/main.py @@ -1,7 +1,8 @@ import os -from flask import Flask -from watchdog.observers import Observer +from flask import Flask, Response +import threading from watchdog.events import FileSystemEventHandler +from watchdog.observers import Observer # -------------- VARIABLES -------------- html_file_path = r"PATH" @@ -12,20 +13,27 @@ scroll_pixels = 100 scroll_interval = 3 # seconds bottom_wait_time = 3 # seconds top_wait_time = 3 # seconds -reload_interval = 35 # seconds # -------------- END VARIABLES -------------- app = Flask(__name__) +file_change_event = threading.Event() class FileChangeHandler(FileSystemEventHandler): - def __init__(self, app): - self.app = app - def on_modified(self, event): if event.src_path == html_file_path: - with self.app.app_context(): - self.app.config["TEMPLATES_AUTO_RELOAD"] = True + file_change_event.set() + + +@app.route("/_file_change") +def file_change_stream(): + def stream(): + while True: + file_change_event.wait() + yield "data: reload\n\n" + file_change_event.clear() + + return Response(stream(), content_type="text/event-stream") @app.route("/") @@ -38,12 +46,11 @@ def serve_html(): scroll-behavior: smooth; }} -