Skip to content

Commit

Permalink
Big changes
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubAndrysek committed Sep 27, 2024
1 parent a35a567 commit 9775a2b
Show file tree
Hide file tree
Showing 65 changed files with 3,495 additions and 214 deletions.
6 changes: 4 additions & 2 deletions .idea/ForrestHub.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ForrestHub-app/ForrestHub-data.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"records": [{"id": 1, "time": "16:16:48", "date": "22/09/2024"}, {"id": 2, "time": "16:16:49", "date": "22/09/2024"}, {"id": 3, "time": "16:16:49", "date": "22/09/2024"}, {"id": 4, "time": "16:16:50", "date": "22/09/2024"}, {"id": 5, "time": "16:24:44", "date": "22. 9. 2024"}, {"id": 6, "time": "4:24:48 PM", "date": "9/22/2024"}, {"id": 7, "time": "22:46:52", "date": "22/09/2024"}, {"id": 8, "time": "22:46:53", "date": "22/09/2024"}, {"id": 9, "time": "22:46:54", "date": "22/09/2024"}, {"id": 10, "time": "22:46:56", "date": "22/09/2024"}, {"id": 11, "time": "22:46:57", "date": "22/09/2024"}, {"id": 12, "time": "22:46:58", "date": "22/09/2024"}, {"id": 13, "time": "22:47:47", "date": "22/09/2024"}, {"id": 14, "time": "22:47:48", "date": "22/09/2024"}, {"id": 15, "time": "22:47:49", "date": "22/09/2024"}], "prijem_queue": [], "odeslani_queue": [], "los_queue": [], "numbersList": ["1234"]}
{"device_8639": {"T\u00fdm A": 1.696, "T\u00fdm B+": 9.591, "T\u00fdm C+": 13.205, "T\u00fdm D+": 200.69199999999998}, "game_config": {"teamCount": 4, "teamNames": ["T\u00fdm A", "T\u00fdm B", "T\u00fdm C", "T\u00fdm D-"], "slowdown": 1000}, "device_1950": {"T\u00fdm A": 0, "T\u00fdm B": 0, "T\u00fdm C": 0, "T\u00fdm D": 0}, "device_9669": {"T\u00fdm A": 1.562, "T\u00fdm B": 14.672999999999998, "T\u00fdm C": 25.554000000000002, "T\u00fdm D": 162.25}, "device_7932": {"T\u00fdm A": 77.605, "T\u00fdm B": 3.4, "T\u00fdm C": null, "T\u00fdm D": 0}, "slowdown": 1000, "device_8412": {"T\u00fdm A": 126.43360000000001, "T\u00fdm B": null, "T\u00fdm C": 1962.7977999999996, "T\u00fdm D": 2.1998}, "device_1502": {"T\u00fdm A": 618.3, "T\u00fdm B": null, "T\u00fdm C": null, "T\u00fdm D": 5961.326700000001}, "device_1011": {"T\u00fdm A": null, "T\u00fdm B": 100.9, "T\u00fdm C": 199.89999999999998, "T\u00fdm D": 55.5}, "device_2292": {"T\u00fdm A": 1, "T\u00fdm B": 1, "T\u00fdm C": 12.962000000000002, "T\u00fdm D-": 2}, "device_4096": {"T\u00fdm A": 0, "T\u00fdm B": 0, "T\u00fdm C": 0, "T\u00fdm D-": 0}, "device_7985": {"T\u00fdm A": 0, "T\u00fdm B": 9.001, "T\u00fdm C": 0.068, "T\u00fdm D-": 0}, "device_3439": {"T\u00fdm A": 6.375, "T\u00fdm B": 4.324, "T\u00fdm C": 5.667, "T\u00fdm D-": 3}, "los_queue": [{"number": 246, "time": "01:58:07", "category": "los_queue"}], "odeslani_queue": [{"number": 360, "time": "01:58:08", "category": "odeslani_queue"}], "numbersList": ["1234", "1233"], "team_times": {"A": 0, "B": 0, "C": 0, "D": 1.251}, "active_team": "D", "records": [{"id": 1, "time": "12:53:55", "date": "27/09/2024"}, {"id": 2, "time": "12:53:55", "date": "27/09/2024"}, {"id": 3, "time": "12:53:56", "date": "27/09/2024"}, {"id": 4, "time": "12:53:56", "date": "27/09/2024"}, {"id": 5, "time": "12:53:57", "date": "27/09/2024"}], "generatedNumber": {"number": 854, "time": "13:07:47"}}
12 changes: 5 additions & 7 deletions ForrestHub-app/app/custom_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,13 @@
class CustomLoader(FileSystemLoader):
def get_source(self, environment, template):
if template.startswith("templates/"):
# {% include 'templates/header.html' %}
if current_app.config.get("LIVE_DATA_USED") and current_app.config.get("LIVE_DATA_FOLDER").exists():
template_path = pathlib.Path(current_app.config["TEMPLATES_FOLDER_LIVE"]) / template[10:]
else:
template_path = pathlib.Path(current_app.config["TEMPLATES_FOLDER"]) / template[10:]
elif current_app.config.get("LIVE_DATA_USED") and Path(current_app.config["GAMES_FOLDER_LIVE"]/template).exists():
template_path = pathlib.Path(current_app.config["TEMPLATES_FOLDER"]) / template[10:]
elif current_app.config.get("LIVE_GAMES_MODE") and Path(current_app.config["GAMES_FOLDER_LIVE"]/template).exists():
template_path = pathlib.Path(current_app.config["GAMES_FOLDER_LIVE"]) / template
elif Path(current_app.config["GAMES_FOLDER"]/template).exists():
template_path = pathlib.Path(current_app.config["GAMES_FOLDER"]) / template
elif Path(current_app.config["PAGES_FOLDER"]/template).exists():
template_path = pathlib.Path(current_app.config["PAGES_FOLDER"]) / template
else:
template_path = pathlib.Path(current_app.config["TEMPLATES_FOLDER"]) / "menu.html"

Expand All @@ -26,7 +24,7 @@ def get_source(self, environment, template):

with open(
template_path, "r", encoding="utf-8"
) as f: # Specify the encoding here
) as f:
source = f.read()
mtime = os.path.getmtime(template_path)
return source, template_path, lambda: mtime == os.path.getmtime(template_path)
5 changes: 2 additions & 3 deletions ForrestHub-app/app/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ def create_app(config_class="config.Config"):
app.config.get("GAMES_FOLDER"),
app.config.get("TEMPLATES_FOLDER"),
app.config.get("ASSETS_FOLDER"),
app.config.get("PAGES_FOLDER"),
]

if app.config.get("LIVE_DATA_USED"):
if app.config.get("LIVE_GAMES_MODE"):
loader_locations.append(app.config.get("GAMES_FOLDER_LIVE"))
loader_locations.append(app.config.get("TEMPLATES_FOLDER_LIVE"))
loader_locations.append(app.config.get("ASSETS_FOLDER_LIVE"))

app.jinja_loader = CustomLoader(loader_locations)

Expand Down
10 changes: 9 additions & 1 deletion ForrestHub-app/app/routes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from http.cookiejar import debug
from pathlib import Path

from app.init import db
Expand All @@ -18,8 +19,11 @@

def get_html_and_folders(folder: Path):
res = []
ignore = [".git", ".vscode", "__pycache__", "node_modules"]
if folder.exists():
for folder_iter in folder.iterdir():
if folder_iter.name in ignore:
continue
if folder_iter.is_dir():
res.append(
{
Expand Down Expand Up @@ -52,7 +56,10 @@ def get_selected_level_routes(folder: str):
@main.route("/")
def index():
return render_template(
"index.html", title="Menu", same_level_routes=get_selected_level_routes(".")
"index.html",
title="Menu",
same_level_routes=get_selected_level_routes("."),
debug=current_app.config.get("DEBUG"),
)


Expand Down Expand Up @@ -125,6 +132,7 @@ def render_page(folder: str, page: str):
data=db.get_data(),
ip_address=get_local_ip_address(),
config=current_app.config,
debug=current_app.config.get("DEBUG"),
same_level_routes=get_selected_level_routes(folder),
)

Expand Down
105 changes: 105 additions & 0 deletions ForrestHub-app/app/socketio_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,22 @@

from app.init import socketio, db

from flask import (
Blueprint,
render_template,
abort,
send_from_directory,
current_app,
jsonify,
request,
)

socketio_bp = Blueprint("socketio", __name__)
connected_clients = 0
connected_admins = 0



game_status = "running"


Expand Down Expand Up @@ -86,3 +98,96 @@ def handle_get_key(json: dict) -> dict:
def handle_delete_key(key: str) -> dict:
db.delete_data_key(key)
return {"status": "ok"}


# add_new_game - create folder with game name
@socketio.on("add_new_game")
def handle_add_new_game(game_name: str) -> dict:
game_folder = current_app.config.get("GAMES_FOLDER")
if not game_folder:
return {"status": "error", "message": "No live data folder"}

game_folder = game_folder / game_name

if game_folder.exists():
return {"status": "error", "message": "Game already exists"}
game_folder.mkdir()
return {"status": "ok"}



# add_new_game_page - create new page in game folder
@socketio.on("add_new_game_page")
def handle_add_new_game_page(json: dict) -> dict:
game_name = json.get("game")
game_page = json.get("page")
page_content = json.get("content")


game_folder = current_app.config.get("GAMES_FOLDER_LIVE")
if not game_folder:
return {"status": "error", "message": "No live data folder"}

game_folder = game_folder / game_name

if not game_folder.exists():
game_folder.mkdir()

page_path = game_folder / f"{game_page}.html"
if page_path.exists():
return {"status": "error", "message": "Page already exists"}

with open(page_path, "w") as f:
f.write(page_content)
return {"status": "ok"}

# get_page_html - get html content of page
@socketio.on("get_page_html")
def handle_get_page_html(json: dict) -> dict:
game_name = json.get("game")
game_page = json.get("page")

game_folder = current_app.config.get("GAMES_FOLDER_LIVE")
if not game_folder:
return {"status": "error", "message": "No live data folder"}

game_folder = game_folder / game_name

if not game_folder.exists():
return {"status": "error", "message": "Tuhle hru nemám k editaci"}

page_path = game_folder / f"{game_page}.html"
if not page_path.exists():
return {"status": "error", "message": "Tuhle stránku hry nemám k editaci"}

with open(page_path, "r") as f:
content = f.read()
return {"status": "ok", "content": content}

# set_page_html - set html content of page
@socketio.on("set_page_html")
def handle_set_page_html(json: dict) -> dict:
game_name = json.get("game")
game_page = json.get("page")
page_content = json.get("content")

header = "{% extends"
if header not in page_content:
return {"status": "error", "message": f"Zapomněli jste přidat {header}... na začátek souboru - mrkni na příklady"}

game_folder = current_app.config.get("GAMES_FOLDER_LIVE")
if not game_folder:
return {"status": "error", "message": "No live data folder"}

game_folder = game_folder / game_name

if not game_folder.exists():
return {"status": "error", "message": "Game does not exist"}

page_path = game_folder / f"{game_page}.html"
if not page_path.exists():
return {"status": "error", "message": "Page does not exist"}

with open(page_path, "w") as f:
f.write(page_content)
return {"status": "ok"}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 9775a2b

Please sign in to comment.