From 878eaf0c4ee0d757d31b67deee0064732405df57 Mon Sep 17 00:00:00 2001 From: Miguel Astor Date: Thu, 26 Feb 2026 01:37:42 -0400 Subject: [PATCH] Extract HTML template to external file with --template option Move embedded HTML template from generate_report.py to platinum.html for easier editing with proper syntax highlighting. Add --template argument to allow selecting different template files. Co-Authored-By: Claude Opus 4.5 --- generate_report.py | 958 +-------------------------------------------- platinum.html | 936 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 956 insertions(+), 938 deletions(-) create mode 100644 platinum.html diff --git a/generate_report.py b/generate_report.py index ee1fb86..64653ab 100644 --- a/generate_report.py +++ b/generate_report.py @@ -21,943 +21,14 @@ import json import sqlite3 from pathlib import Path -HTML_TEMPLATE = """ - - - - - Lutris Playtime Report - - - - -
-
-
-
Lutris Playtime Report
-
-
-
-
-
-
-
- -
-
-
-
Statistics
-
-
-
-
-
-
-
__TOTAL_LIBRARY__
-
Games in Library
-
-
-
0
-
Games Played
-
-
-
0h
-
Total Playtime
-
-
-
-
- -
-
-
-
Playtime Distribution
-
-
-
-
-
-
-
Top Games
- -
-
-
By Category
- -
-
-
-
- -
-
-
-
Summaries
-
-
-
-
-
-
Top Games
-
By Category
-
-
-
-
- - - - - - - - - - -
#GamePlaytime%
-
-
-
-
- - - - - - - - - - -
#CategoryPlaytime%
-
-
-
-
-
- - - - -""" +def load_template(template_file: str) -> str: + """Load the HTML template from the specified file.""" + template_path = SCRIPT_DIR / template_file + return template_path.read_text(encoding="utf-8") def load_asset_as_base64(path: Path, mime_type: str) -> str: @@ -1011,7 +82,7 @@ def get_all_games(db_path: str) -> tuple[list[dict], int]: return games, total_library -def generate_report(db_path: str, output_path: str, top_n: int, assets_dir: str, bg_image_path: str = None) -> None: +def generate_report(db_path: str, output_path: str, top_n: int, assets_dir: str, template_file: str, bg_image_path: str = None) -> None: """Generate the HTML report.""" all_games, total_library = get_all_games(db_path) @@ -1053,7 +124,8 @@ def generate_report(db_path: str, output_path: str, top_n: int, assets_dir: str, tab_active = load_asset_as_base64(assets_path / "Tabs" / "tab-top-active.png", "image/png") tab_inactive = load_asset_as_base64(assets_path / "Tabs" / "tab-top.png", "image/png") - html = HTML_TEMPLATE.replace("__ALL_GAMES__", json.dumps(all_games)) + html = load_template(template_file) + html = html.replace("__ALL_GAMES__", json.dumps(all_games)) html = html.replace("__TOP_N__", str(top_n)) html = html.replace("__TOTAL_LIBRARY__", str(total_library)) html = html.replace("__FONT_CHARCOAL__", font_charcoal) @@ -1110,6 +182,11 @@ def main(): default=None, help="Path to background image for tiling (default: Platinum stripes pattern)" ) + parser.add_argument( + "--template", + default="platinum.html", + help="HTML template file to use (default: platinum.html)" + ) args = parser.parse_args() @@ -1121,7 +198,12 @@ def main(): print(f"Error: Assets directory not found: {args.assets}") return 1 - generate_report(args.db, args.output, args.top, args.assets, args.background) + template_path = SCRIPT_DIR / args.template + if not template_path.exists(): + print(f"Error: Template file not found: {template_path}") + return 1 + + generate_report(args.db, args.output, args.top, args.assets, args.template, args.background) return 0 diff --git a/platinum.html b/platinum.html new file mode 100644 index 0000000..d9dec01 --- /dev/null +++ b/platinum.html @@ -0,0 +1,936 @@ + + + + + + Lutris Playtime Report + + + + +
+
+
+
Lutris Playtime Report
+
+
+
+
+
+
+
+ +
+
+
+
Statistics
+
+
+
+
+
+
+
__TOTAL_LIBRARY__
+
Games in Library
+
+
+
0
+
Games Played
+
+
+
0h
+
Total Playtime
+
+
+
+
+ +
+
+
+
Playtime Distribution
+
+
+
+
+
+
+
Top Games
+ +
+
+
By Category
+ +
+
+
+
+ +
+
+
+
Summaries
+
+
+
+
+
+
Top Games
+
By Category
+
+
+
+
+ + + + + + + + + + +
#GamePlaytime%
+
+
+
+
+ + + + + + + + + + +
#CategoryPlaytime%
+
+
+
+
+
+ + + +