updated main.py for oe11 encoding
This commit is contained in:
25
main.py
25
main.py
@@ -4,10 +4,10 @@ from watchdog.observers import Observer
|
|||||||
from watchdog.events import FileSystemEventHandler
|
from watchdog.events import FileSystemEventHandler
|
||||||
|
|
||||||
# -------------- VARIABLES --------------
|
# -------------- VARIABLES --------------
|
||||||
html_file_path = r'PATH'
|
html_file_path = r"PATH"
|
||||||
host = '0.0.0.0'
|
host = "0.0.0.0"
|
||||||
port = 80
|
port = 80
|
||||||
is_oe11 = True # if using OE11 set it to True, for OE12 set it to False (encoding)
|
is_oe11 = True # if using OE11 set it to True, for OE12 set it to False (encoding)
|
||||||
scroll_pixels = 100
|
scroll_pixels = 100
|
||||||
scroll_interval = 3 # seconds
|
scroll_interval = 3 # seconds
|
||||||
bottom_wait_time = 3 # seconds
|
bottom_wait_time = 3 # seconds
|
||||||
@@ -17,6 +17,7 @@ reload_interval = 35 # seconds
|
|||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
class FileChangeHandler(FileSystemEventHandler):
|
class FileChangeHandler(FileSystemEventHandler):
|
||||||
def __init__(self, app):
|
def __init__(self, app):
|
||||||
self.app = app
|
self.app = app
|
||||||
@@ -24,13 +25,14 @@ class FileChangeHandler(FileSystemEventHandler):
|
|||||||
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():
|
with self.app.app_context():
|
||||||
self.app.config['TEMPLATES_AUTO_RELOAD'] = True
|
self.app.config["TEMPLATES_AUTO_RELOAD"] = True
|
||||||
|
|
||||||
@app.route('/')
|
|
||||||
|
@app.route("/")
|
||||||
def serve_html():
|
def serve_html():
|
||||||
with open(html_file_path, 'r', encoding= ('latin-1' if is_oe11 else 'utf-8') ) as file:
|
with open(html_file_path, "r", encoding=("cp1252" if is_oe11 else "utf-8")) as file:
|
||||||
content = file.read()
|
content = file.read()
|
||||||
content += f'''
|
content += f"""
|
||||||
<style>
|
<style>
|
||||||
html {{
|
html {{
|
||||||
scroll-behavior: smooth;
|
scroll-behavior: smooth;
|
||||||
@@ -80,13 +82,16 @@ def serve_html():
|
|||||||
}}
|
}}
|
||||||
}};
|
}};
|
||||||
</script>
|
</script>
|
||||||
'''
|
"""
|
||||||
return content
|
return content
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
|
if __name__ == "__main__":
|
||||||
event_handler = FileChangeHandler(app)
|
event_handler = FileChangeHandler(app)
|
||||||
observer = Observer()
|
observer = Observer()
|
||||||
observer.schedule(event_handler, path=os.path.dirname(html_file_path), recursive=False)
|
observer.schedule(
|
||||||
|
event_handler, path=os.path.dirname(html_file_path), recursive=False
|
||||||
|
)
|
||||||
observer.start()
|
observer.start()
|
||||||
try:
|
try:
|
||||||
app.run(host=host, port=port)
|
app.run(host=host, port=port)
|
||||||
|
|||||||
Reference in New Issue
Block a user