Files
pokerfreak/mock/vorlage.py
T
mmintel 836c16c9a4 Sprechweise geputzt: kein echt/live/Mensch mehr in Kommentaren und Texten
Die Welt soll nichts verraten. Woerter, die ein Gegenueber implizieren (echt vs. unecht,
live, Mensch), sind aus Prosa, Kommentaren und Docstrings raus; Namen (mensch_ruhe_s,
echte_chops) und der Altwert "echt" im Spielplan bleiben. Nur Kommentare und Docstrings
angefasst, damit keine Einrueckung faellt.
2026-11-01 22:11:05 +01:00

98 lines
3.3 KiB
Python

#!/usr/bin/env python3
"""Zieht die Vorlage für den Klon direkt aus der App.
Kein Abschreiben: die Lobby ist ein DOM und über das Debug-Port abfragbar.
Dazu Logzeilen aus dem Archiv als Beispiele.
python3 mock/vorlage.py
"""
import json
import os
import re
import subprocess
import sys
_w = os.path.dirname(os.path.abspath(__file__))
while _w != "/" and not os.path.isdir(os.path.join(_w, "lesen")):
_w = os.path.dirname(_w)
WURZEL = _w
for _u in ("lobby", "lesen", "hand", "client"):
_q = os.path.join(_w, _u)
if os.path.isdir(_q) and _q not in sys.path:
sys.path.insert(0, _q)
ZIEL = os.path.join(WURZEL, "mock", "vorlage")
ARCHIV = os.path.join(WURZEL, "archiv")
CDP = os.path.join(WURZEL, "lobby", "cdp.mjs")
JS = """(() => {
const formen = new Map();
for (const e of document.querySelectorAll('*')) {
const schluessel = e.tagName + '|' + [...e.classList].sort().join('.') + '|' +
Object.keys(e.dataset).sort().join(',');
if (!formen.has(schluessel)) formen.set(schluessel, e.outerHTML.replace(/\\s+/g, ' ').slice(0, 240));
}
const klassen = [...new Set([...document.querySelectorAll('*')].flatMap(e => [...e.classList]))].sort();
const text = document.body.innerText.replace(/\\s+/g, ' ').slice(0, 1200);
return JSON.stringify({ klassen, formen: [...formen.entries()].slice(0, 70), text }, null, 1);
})()"""
BEISPIELE = ("game.user_turn", "game.hole_cards", "game.dealer_cards", "game.potInfo",
"game.seat", "game.game_alldata", "chrome")
def lobby_struktur():
r = subprocess.run(["node", CDP, "--eval", JS], capture_output=True, text=True, cwd=WURZEL)
roh = (r.stdout or "").strip()
try:
return json.loads(roh)
except Exception:
return {"fehler": roh[:200]}
def log_beispiele(je=3):
zeilen = []
for pfad in sorted(os.listdir(ARCHIV))[:6]:
if not pfad.endswith(".log"):
continue
for zeile in open(os.path.join(ARCHIV, pfad), errors="replace"):
for muster in BEISPIELE:
if muster == "chrome":
if "[Method] ->" in zeile and not any(b in zeile for b in BEISPIELE):
zeilen.append(("chrome", zeile.strip()[:400]))
continue
if f'"Cmd":"{muster}"' in zeile:
zeilen.append((muster, zeile.strip()[:400]))
gesammelt = {}
for art, zeile in zeilen:
gesammelt.setdefault(art, [])
if len(gesammelt[art]) < je:
gesammelt[art].append(zeile)
return gesammelt
def main():
os.makedirs(ZIEL, exist_ok=True)
struktur = lobby_struktur()
open(os.path.join(ZIEL, "dom-lobby.json"), "w").write(
json.dumps(struktur, ensure_ascii=False, indent=1))
print("Lobby: Klassen", len(struktur.get("klassen", [])),
"| Formen", len(struktur.get("formen", [])))
beispiele = log_beispiele()
with open(os.path.join(ZIEL, "log-beispiele.txt"), "w") as f:
for art, zeilen in beispiele.items():
f.write(f"### {art}\n")
for z in zeilen:
f.write(z + "\n")
f.write("\n")
print("Logbeispiele:", {k: len(v) for k, v in beispiele.items()})
for name in ("dom-lobby.json", "log-beispiele.txt"):
p = os.path.join(ZIEL, name)
print(f" {name}: {os.path.getsize(p)} Bytes")
if __name__ == "__main__":
main()