#!/usr/bin/env python3 """Generate HTML gallery for indkorsel person-detection snapshots. Called via shell_command after each new snapshot is saved. Output: /config/www/snapshots/indkorsel_gallery.html """ import os import glob from datetime import datetime SNAPSHOT_DIR = "/config/www/snapshots/indkorsel" OUTPUT_FILE = "/config/www/snapshots/indkorsel_gallery.html" LOADER_FILE = "/config/www/snapshots/indkorsel_loader.html" MAX_SNAPSHOTS = 100 def parse_timestamp(filename): base = os.path.basename(filename).replace(".jpg", "") try: dt = datetime.strptime(base, "%Y-%m-%d_%H-%M-%S") return dt.strftime("%-d. %b %Y %H:%M:%S") except Exception: return base os.makedirs(SNAPSHOT_DIR, exist_ok=True) files = sorted( [f for f in glob.glob(os.path.join(SNAPSHOT_DIR, "*.jpg")) if os.path.basename(f) != "latest.jpg"], reverse=True )[:MAX_SNAPSHOTS] items_html = "" images_js = [] # [{src, ts}, ...] for JS navigation for f in files: rel = "/local/snapshots/indkorsel/" + os.path.basename(f) ts = parse_timestamp(f) idx = len(images_js) items_html += f"""