#!/usr/bin/env python3 """Build the standalone single-file dashboard. Reads the Flask templates/CSS/JS and fuses them into one self-contained .html: no server, no external requests, works from file://, a static host, or an e-mail. python3 standalone/build_standalone.py → ../cadence-dashboard.html """ from pathlib import Path import re import sys HERE = Path(__file__).resolve().parent ROOT = HERE.parent # /home/user/cadence OUT = ROOT.parent / "cadence-dashboard.html" html = (ROOT / "templates" / "dashboard.html").read_text() css = (ROOT / "static" / "dash.css").read_text() dash = (ROOT / "static" / "dash.js").read_text() runtime = (HERE / "runtime.js").read_text() # ── 1. dashboard.js → reroute every network touchpoint through the runtime ── subs = [ # data source ("""async function api(path, opts) { const r = await fetch(path, opts); let data = null; try { data = await r.json(); } catch {} if (!r.ok) { const err = new Error((data && data.error) || `Request failed (${r.status})`); err.status = r.status; err.code = data && data.code; err.hint = data && data.hint; throw err; } return data; }""", """async function api(path, opts) { return window.__SRC__.api(path, opts); }"""), # artwork ("const thumb = vid => `/api/thumb/${vid}`;", "const thumb = vid => window.__SRC__.thumb(vid);"), ("const imgp = u => `/api/img?u=${encodeURIComponent(u)}`;", "const imgp = u => window.__SRC__.img(u);"), # the media element (real