37 lines
1.6 KiB
Python
37 lines
1.6 KiB
Python
import os as _os, sys as _sys
|
|
_w = _os.path.dirname(_os.path.abspath(__file__))
|
|
while _w != "/" and not _os.path.isdir(_os.path.join(_w, "hand")):
|
|
_w = _os.path.dirname(_w)
|
|
WURZEL = _w
|
|
for _u in ("lesen", "entscheiden", "hand", "lobby", "korpus", "betrieb", "mock"):
|
|
_q = _os.path.join(_w, _u)
|
|
if _os.path.isdir(_q) and _q not in _sys.path:
|
|
_sys.path.insert(0, _q)
|
|
import json, os, select, subprocess, sys, time
|
|
S = os.path.expanduser("~/Projects/pokerfreak-shell")
|
|
p = subprocess.Popen(["bash", os.path.join(S, "run.sh")], stdin=subprocess.PIPE,
|
|
stdout=subprocess.PIPE, stderr=subprocess.DEVNULL, text=True, bufsize=1, cwd=S)
|
|
def send(o): p.stdin.write(json.dumps(o) + "\n"); p.stdin.flush()
|
|
def read(sek=60):
|
|
ende = time.time() + sek
|
|
while time.time() < ende:
|
|
if select.select([p.stdout], [], [], 0.3)[0]:
|
|
z = p.stdout.readline()
|
|
if z.strip():
|
|
try: return json.loads(z)
|
|
except Exception: return {"raw": z[:200]}
|
|
return None
|
|
def call(nr, name, args=None):
|
|
send({"jsonrpc":"2.0","id":nr,"method":"tools/call","params":{"name":name,"arguments":args or {}}})
|
|
a = read() or {}
|
|
t = ((a.get("result") or {}).get("content") or [{}])[0].get("text", "")
|
|
print(f"### {name} -> {t[:300]}")
|
|
send({"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"p","version":"1"}}})
|
|
read(15); send({"jsonrpc":"2.0","method":"notifications/initialized","params":{}})
|
|
call(2, "close_all_tables")
|
|
time.sleep(3)
|
|
call(3, "open_practice_table")
|
|
time.sleep(8)
|
|
call(4, "status")
|
|
p.terminate()
|