#!/usr/bin/env bash # Screenshot der App fuer Doku/README (headless Chromium). # # Nutzung: # tools/screenshot.sh [--view today|history] [--size 1280x1080] # [--out PFAD] [--full] # # --view today (Standard, mit Beispiel-Session) oder history (Demo-Verlauf) # --size Fenstergroesse, z.B. 390x844 fuer die Handy-Ansicht # --out Zieldatei (Standard: tools/screenshot.png) # --full heutige Ansicht mit ALLEN Uebungen befuellt (nicht nur ein paar) # # Voraussetzungen: python3, curl, chromium (oder chromium-browser). set -euo pipefail BASE="$(cd "$(dirname "$0")/.." && pwd)" VIEW=today SIZE=1280x1080 OUT="$BASE/tools/screenshot.png" FULL=0 PORT=8097 while [ $# -gt 0 ]; do case "$1" in --view) VIEW="$2"; shift 2;; --size) SIZE="$2"; shift 2;; --out) OUT="$2"; shift 2;; --full) FULL=1; shift;; *) echo "unbekannte Option: $1" >&2; exit 1;; esac done STATE="$(mktemp -d)" TRAINING_STATE_DIR="$STATE" PORT="$PORT" python3 "$BASE/server.py" >"$STATE/log" 2>&1 & SRV=$! trap 'kill "$SRV" 2>/dev/null || true; rm -rf "$STATE"' EXIT sleep 1.2 B="http://127.0.0.1:$PORT" if [ "$VIEW" = "history" ]; then curl -s -X PUT "$B/api/settings" -H 'Content-Type: application/json' \ -d '{"setupDone":true,"startTab":"history"}' >/dev/null python3 - "$B" "$BASE" <<'PY' import json, sys, urllib.request B, base = sys.argv[1], sys.argv[2] demo = json.load(open(base + "/demo-data.json", encoding="utf-8")) data = json.dumps({"format": "trainingsplan-export-v2", "data": json.dumps(demo)}).encode() urllib.request.urlopen(urllib.request.Request( B + "/api/import", data=data, headers={"Content-Type": "application/json"}, method="POST")).read() PY else curl -s -X PUT "$B/api/settings" -H 'Content-Type: application/json' \ -d '{"setupDone":true}' >/dev/null python3 - "$B" "$FULL" <<'PY' import json, sys, urllib.request B, full = sys.argv[1], sys.argv[2] == "1" sid = json.load(urllib.request.urlopen(urllib.request.Request( B + "/api/sessions", data=json.dumps({"activity": "gym", "day": "Push"}).encode(), headers={"Content-Type": "application/json"}, method="POST")))["id"] small = { "Push/Bankdrücken KH (je Hand)": [("18,5", "10"), ("18,5", "10"), ("20", "8"), ("20", "6")], "Push/Schrägbank KH (je Hand)": [("14", "12"), ("14", "10")], "Push/Pectoral/Butterfly": [("20", "15")], } big = { "Push/Bankdrücken KH (je Hand)": [("18,5", "10"), ("18,5", "10"), ("20", "8"), ("20", "6")], "Push/Schrägbank KH (je Hand)": [("14", "12"), ("14", "10"), ("14", "10")], "Push/Pectoral/Butterfly": [("20", "15"), ("20", "15"), ("25", "12")], "Push/Seitheben (je Hand)": [("8", "15"), ("8", "14"), ("8", "12")], "Push/Schulterpresse Maschine": [("25", "12"), ("30", "10"), ("30", "9")], "Push/Kabel-Trizeps-Pushdown": [("25", "15"), ("25", "14"), ("27,5", "12")], "Push/Trizeps-Strecken (French Press Maschine)": [("15", "15"), ("15", "12"), ("15", "12")], "Push/Kabel-Curls (Bizeps)": [("15", "15"), ("15", "14"), ("17,5", "12")], } data = big if full else small sets = [{"exercise": ex, "sort": i, "weight": w, "reps": r, "done": 1} for ex, lst in data.items() for i, (w, r) in enumerate(lst)] urllib.request.urlopen(urllib.request.Request( B + "/api/sessions/" + str(sid), data=json.dumps({"sets": sets}).encode(), headers={"Content-Type": "application/json"}, method="PATCH")).read() PY fi CHROME="$(command -v chromium || command -v chromium-browser)" WS="${SIZE/x/,}" "$CHROME" --headless=new --no-sandbox --disable-gpu --hide-scrollbars \ --virtual-time-budget=6000 --window-size="$WS" --screenshot="$OUT" "$B/" \ >/dev/null 2>&1 || \ "$CHROME" --headless --no-sandbox --disable-gpu --hide-scrollbars \ --virtual-time-budget=6000 --window-size="$WS" --screenshot="$OUT" "$B/" \ >/dev/null 2>&1 echo "geschrieben: $OUT"