auto reload at file change
This commit is contained in:
@@ -9,7 +9,7 @@ Use it to display the results on a TV or to serve results for the competitors.
|
|||||||
<ul style="list-style-type: none"> ✅ Customizable auto-scroll (see Variables section) </ul>
|
<ul style="list-style-type: none"> ✅ Customizable auto-scroll (see Variables section) </ul>
|
||||||
<ul style="list-style-type: none"> ✅ Smooth scrolling </ul>
|
<ul style="list-style-type: none"> ✅ Smooth scrolling </ul>
|
||||||
<ul style="list-style-type: none"> ✅ Auto-reload at bottom </ul>
|
<ul style="list-style-type: none"> ✅ Auto-reload at bottom </ul>
|
||||||
<ul style="list-style-type: none"> ✅ Auto-reload at X seconds when no need for scrolling </ul>
|
<ul style="list-style-type: none"> ✅ Auto-reload at file change when no need for scrolling </ul>
|
||||||
<ul style="list-style-type: none"> ✅ Supports OE11 and OE12 exported HTML </ul>
|
<ul style="list-style-type: none"> ✅ Supports OE11 and OE12 exported HTML </ul>
|
||||||
<ul style="list-style-type: none"> ✅ File serving on localhost and LAN </ul>
|
<ul style="list-style-type: none"> ✅ File serving on localhost and LAN </ul>
|
||||||
|
|
||||||
@@ -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
|
- `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
|
- `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
|
- `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
|
## Getting Started
|
||||||
|
|
||||||
@@ -80,4 +79,4 @@ This project is licensed under the MIT License - see the `LICENSE` file for deta
|
|||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p style="text-align: center;"> Made with ❤️ on 603 NYÍRSÉG IC </p>
|
<p style="text-align: center;"> Made with ❤️ and ☕ on 603 NYÍRSÉG IC </p>
|
||||||
@@ -9,7 +9,7 @@ Egyszerű python program, amivel a tájfutó eseményeken használt OE11 és OE1
|
|||||||
<ul style="list-style-type: none"> ✅ Személyre szabható automatikus görgetés </ul>
|
<ul style="list-style-type: none"> ✅ Személyre szabható automatikus görgetés </ul>
|
||||||
<ul style="list-style-type: none"> ✅ Finom görgetés </ul>
|
<ul style="list-style-type: none"> ✅ Finom görgetés </ul>
|
||||||
<ul style="list-style-type: none"> ✅ Automatikus újratöltés a lap alján </ul>
|
<ul style="list-style-type: none"> ✅ Automatikus újratöltés a lap alján </ul>
|
||||||
<ul style="list-style-type: none"> ✅ Automatikus újratöltés, ha nincs szükség görgetésre </ul>
|
<ul style="list-style-type: none"> ✅ Automatikus újratöltés fájl változáskor, ha nincs szükség görgetésre </ul>
|
||||||
<ul style="list-style-type: none"> ✅ Támogatja az OE11 és OE12-ből exportált HTML fájlokat is </ul>
|
<ul style="list-style-type: none"> ✅ Támogatja az OE11 és OE12-ből exportált HTML fájlokat is </ul>
|
||||||
<ul style="list-style-type: none"> ✅ Megjeleníti a fájlt localhost-on és a helyi hálózaton is </ul>
|
<ul style="list-style-type: none"> ✅ Megjeleníti a fájlt localhost-on és a helyi hálózaton is </ul>
|
||||||
|
|
||||||
@@ -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
|
- `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
|
- `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
|
- `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
|
## Használat
|
||||||
|
|
||||||
@@ -80,4 +79,4 @@ Ez a projekt az MIT Licensz alatt van licenszelve - részletekért lásd a LICEN
|
|||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
<p style="text-align: center;"> Készült sok ❤️-el a 603 NYÍRSÉG IC-n </p>
|
<p style="text-align: center;"> Készült sok ❤️-el és ☕-val a 603 NYÍRSÉG IC-n </p>
|
||||||
34
main.py
34
main.py
@@ -1,7 +1,8 @@
|
|||||||
import os
|
import os
|
||||||
from flask import Flask
|
from flask import Flask, Response
|
||||||
from watchdog.observers import Observer
|
import threading
|
||||||
from watchdog.events import FileSystemEventHandler
|
from watchdog.events import FileSystemEventHandler
|
||||||
|
from watchdog.observers import Observer
|
||||||
|
|
||||||
# -------------- VARIABLES --------------
|
# -------------- VARIABLES --------------
|
||||||
html_file_path = r"PATH"
|
html_file_path = r"PATH"
|
||||||
@@ -12,20 +13,27 @@ scroll_pixels = 100
|
|||||||
scroll_interval = 3 # seconds
|
scroll_interval = 3 # seconds
|
||||||
bottom_wait_time = 3 # seconds
|
bottom_wait_time = 3 # seconds
|
||||||
top_wait_time = 3 # seconds
|
top_wait_time = 3 # seconds
|
||||||
reload_interval = 35 # seconds
|
|
||||||
# -------------- END VARIABLES --------------
|
# -------------- END VARIABLES --------------
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
file_change_event = threading.Event()
|
||||||
|
|
||||||
|
|
||||||
class FileChangeHandler(FileSystemEventHandler):
|
class FileChangeHandler(FileSystemEventHandler):
|
||||||
def __init__(self, app):
|
|
||||||
self.app = app
|
|
||||||
|
|
||||||
def on_modified(self, event):
|
def on_modified(self, event):
|
||||||
if event.src_path == html_file_path:
|
if event.src_path == html_file_path:
|
||||||
with self.app.app_context():
|
file_change_event.set()
|
||||||
self.app.config["TEMPLATES_AUTO_RELOAD"] = True
|
|
||||||
|
|
||||||
|
@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("/")
|
@app.route("/")
|
||||||
@@ -38,12 +46,11 @@ def serve_html():
|
|||||||
scroll-behavior: smooth;
|
scroll-behavior: smooth;
|
||||||
}}
|
}}
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
let scrollAmount = {scroll_pixels};
|
let scrollAmount = {scroll_pixels};
|
||||||
let scrollInterval = {scroll_interval} * 1000;
|
let scrollInterval = {scroll_interval} * 1000;
|
||||||
let bottomWaitTime = {bottom_wait_time} * 1000;
|
let bottomWaitTime = {bottom_wait_time} * 1000;
|
||||||
let topWaitTime = {top_wait_time} * 1000;
|
let topWaitTime = {top_wait_time} * 1000;
|
||||||
let reloadInterval = {reload_interval} * 1000;
|
|
||||||
let scrollPos = 0;
|
let scrollPos = 0;
|
||||||
let scrollingDown = true;
|
let scrollingDown = true;
|
||||||
|
|
||||||
@@ -76,7 +83,10 @@ def serve_html():
|
|||||||
window.onload = function() {{
|
window.onload = function() {{
|
||||||
window.scrollTo(0, 0);
|
window.scrollTo(0, 0);
|
||||||
if (document.body.scrollHeight <= window.innerHeight) {{
|
if (document.body.scrollHeight <= window.innerHeight) {{
|
||||||
setTimeout(reloadPage, reloadInterval);
|
const eventSource = new EventSource('/_file_change');
|
||||||
|
eventSource.onmessage = function() {{
|
||||||
|
location.reload();
|
||||||
|
}};
|
||||||
}} else {{
|
}} else {{
|
||||||
setTimeout(autoScroll, topWaitTime);
|
setTimeout(autoScroll, topWaitTime);
|
||||||
}}
|
}}
|
||||||
@@ -87,7 +97,7 @@ def serve_html():
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
event_handler = FileChangeHandler(app)
|
event_handler = FileChangeHandler()
|
||||||
observer = Observer()
|
observer = Observer()
|
||||||
observer.schedule(
|
observer.schedule(
|
||||||
event_handler, path=os.path.dirname(html_file_path), recursive=False
|
event_handler, path=os.path.dirname(html_file_path), recursive=False
|
||||||
|
|||||||
Reference in New Issue
Block a user