Tischliste aus der API statt aus der Lobby: lesen/raumliste.py
Die Lobby im Client verliert ihre Liste (live 31.10.). Die Daten haben eine eigene, stabile Quelle: POST /get-cash-lobby-list mit dem Token des laufenden Clients - je Tisch Blinds, Buy-in-Grenzen, Hausregel-Schalter und serverAddress (die SFS-Adresse samt Port JE TISCH). raumliste.zeilen() schreibt sie in das Format, das lobby/auswahl.py liest - damit faellt die Wahl auf denselben Regeln wie bisher, nur aus einer Quelle, die die Oberflaeche nicht braucht. Der Beleg ist woertlich gesichert (archiv/echt/beispiel-lobby.json, echte Antwort).
This commit is contained in:
@@ -0,0 +1,170 @@
|
||||
{
|
||||
"api_version": "3.6.0",
|
||||
"data": [
|
||||
{
|
||||
"roomName": "14R NL6 0.02 INRIT-(A) 1662043",
|
||||
"tableId": 1662043,
|
||||
"configId": 202289,
|
||||
"serverAddress": "poker-cash-0.coinpoker.ai:443;HELM_REVERSION1;2d3109c1-68cf-40a0-b0c1-d1d24416f695;poker-nlb.coinpoker.ai:7000",
|
||||
"maxSize": 2000,
|
||||
"minSize": 2,
|
||||
"coinTypeId": 1,
|
||||
"gameType": "Ring",
|
||||
"miniGameTypeId": 18,
|
||||
"isAnonymous": false,
|
||||
"isRit": false,
|
||||
"joinedUserCount": 0,
|
||||
"maxBuyIn": 2,
|
||||
"minBuyIn": 0.8,
|
||||
"bigBlind": 0.02,
|
||||
"smallBlind": 0,
|
||||
"lobbyId": 1,
|
||||
"gameVarient": "TexasSixPlus",
|
||||
"averageStack": 0,
|
||||
"tableSize": 6,
|
||||
"isTurbo": false,
|
||||
"isBombpot": false,
|
||||
"isFixedHandBombpot": false,
|
||||
"runId": 0,
|
||||
"handsInBombpot": null,
|
||||
"bombpotInducesDoubleBoard": false,
|
||||
"invitedTable": true,
|
||||
"isEVChopAllowed": false,
|
||||
"iRitOptions": [
|
||||
0,
|
||||
1,
|
||||
2
|
||||
],
|
||||
"metadata": {
|
||||
"theme": null,
|
||||
"iconImage": null
|
||||
},
|
||||
"isDoubleBoard": false,
|
||||
"isMustShowEnabled": false,
|
||||
"ante": 0.02,
|
||||
"mainLobbyServerAddress": "poker-mainlobby-0.coinpoker.ai:443;HELM_REVERSION1;cd070487-c425-47a2-9ca5-cc1ce08d5736;poker-nlb.coinpoker.ai:9000",
|
||||
"isRestricted": false,
|
||||
"allowedUsers": null,
|
||||
"isCgwc": false,
|
||||
"isArena": false,
|
||||
"isBattle": false,
|
||||
"isNoLimp": false,
|
||||
"isKPoker": false,
|
||||
"isSessionMinVPIPEnabledWithBanInterval": false,
|
||||
"sessionMinVPIPBanInterval": 0,
|
||||
"specialPlayerCount": 0,
|
||||
"isShowPublicly": true,
|
||||
"isPasswordProtected": false
|
||||
},
|
||||
{
|
||||
"roomName": "14R PLO6 0.01-0.02 EV-INRIT (A) 1684499",
|
||||
"tableId": 1684499,
|
||||
"configId": 202219,
|
||||
"serverAddress": "poker-cash-0.coinpoker.ai:443;HELM_REVERSION1;2d3109c1-68cf-40a0-b0c1-d1d24416f695;poker-nlb.coinpoker.ai:7000",
|
||||
"maxSize": 2000,
|
||||
"minSize": 2,
|
||||
"coinTypeId": 1,
|
||||
"gameType": "Ring",
|
||||
"miniGameTypeId": 20,
|
||||
"isAnonymous": false,
|
||||
"isRit": false,
|
||||
"joinedUserCount": 2,
|
||||
"maxBuyIn": 2,
|
||||
"minBuyIn": 0.8,
|
||||
"bigBlind": 0.02,
|
||||
"smallBlind": 0.01,
|
||||
"lobbyId": 1,
|
||||
"gameVarient": "6CardPLO",
|
||||
"averageStack": 0,
|
||||
"tableSize": 5,
|
||||
"isTurbo": false,
|
||||
"isBombpot": false,
|
||||
"isFixedHandBombpot": false,
|
||||
"runId": 0,
|
||||
"handsInBombpot": null,
|
||||
"bombpotInducesDoubleBoard": false,
|
||||
"invitedTable": true,
|
||||
"isEVChopAllowed": true,
|
||||
"iRitOptions": [
|
||||
0,
|
||||
1,
|
||||
2
|
||||
],
|
||||
"metadata": {
|
||||
"theme": null,
|
||||
"iconImage": null
|
||||
},
|
||||
"isDoubleBoard": false,
|
||||
"isMustShowEnabled": false,
|
||||
"ante": 0,
|
||||
"mainLobbyServerAddress": "poker-mainlobby-0.coinpoker.ai:443;HELM_REVERSION1;cd070487-c425-47a2-9ca5-cc1ce08d5736;poker-nlb.coinpoker.ai:9000",
|
||||
"isRestricted": false,
|
||||
"allowedUsers": null,
|
||||
"isCgwc": false,
|
||||
"isArena": false,
|
||||
"isBattle": false,
|
||||
"isNoLimp": false,
|
||||
"isKPoker": false,
|
||||
"isSessionMinVPIPEnabledWithBanInterval": false,
|
||||
"sessionMinVPIPBanInterval": 0,
|
||||
"specialPlayerCount": 0,
|
||||
"isShowPublicly": true,
|
||||
"isPasswordProtected": false
|
||||
},
|
||||
{
|
||||
"roomName": "14R PLO5 HU 0.01-0.02 EV-INRIT (A) 1673393",
|
||||
"tableId": 1673393,
|
||||
"configId": 202152,
|
||||
"serverAddress": "poker-cash-2.coinpoker.ai:443;HELM_REVERSION1;02b98152-3cba-4b65-8744-cef0b55315f5;poker-nlb.coinpoker.ai:7002",
|
||||
"maxSize": 2000,
|
||||
"minSize": 2,
|
||||
"coinTypeId": 1,
|
||||
"gameType": "Ring",
|
||||
"miniGameTypeId": 17,
|
||||
"isAnonymous": false,
|
||||
"isRit": false,
|
||||
"joinedUserCount": 0,
|
||||
"maxBuyIn": 2,
|
||||
"minBuyIn": 0.8,
|
||||
"bigBlind": 0.02,
|
||||
"smallBlind": 0.01,
|
||||
"lobbyId": 1,
|
||||
"gameVarient": "5CardPLO",
|
||||
"averageStack": 0,
|
||||
"tableSize": 2,
|
||||
"isTurbo": false,
|
||||
"isBombpot": false,
|
||||
"isFixedHandBombpot": false,
|
||||
"runId": 0,
|
||||
"handsInBombpot": null,
|
||||
"bombpotInducesDoubleBoard": false,
|
||||
"invitedTable": true,
|
||||
"isEVChopAllowed": true,
|
||||
"iRitOptions": [
|
||||
0,
|
||||
1,
|
||||
2
|
||||
],
|
||||
"metadata": {
|
||||
"theme": null,
|
||||
"iconImage": null
|
||||
},
|
||||
"isDoubleBoard": false,
|
||||
"isMustShowEnabled": false,
|
||||
"ante": 0,
|
||||
"mainLobbyServerAddress": "poker-mainlobby-0.coinpoker.ai:443;HELM_REVERSION1;cd070487-c425-47a2-9ca5-cc1ce08d5736;poker-nlb.coinpoker.ai:9000",
|
||||
"isRestricted": false,
|
||||
"allowedUsers": null,
|
||||
"isCgwc": false,
|
||||
"isArena": false,
|
||||
"isBattle": false,
|
||||
"isNoLimp": false,
|
||||
"isKPoker": false,
|
||||
"isSessionMinVPIPEnabledWithBanInterval": false,
|
||||
"sessionMinVPIPBanInterval": 0,
|
||||
"specialPlayerCount": 0,
|
||||
"isShowPublicly": true,
|
||||
"isPasswordProtected": false
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
"""Die Tischliste von aussen - ohne Lobby-Oberflaeche, ohne Lobby-Verbindung.
|
||||
|
||||
Die Lobby im Client verliert ihre Liste gern (live 31.10.). Die Daten haben aber eine eigene,
|
||||
stabile Quelle: `POST /get-cash-lobby-list` beim Listing-Dienst, mit dem Firebase-Token des
|
||||
laufenden Clients. Gelesen wird, was der Dienst ohnehin liefert - je Tisch Name, Id, Blinds,
|
||||
Buy-in-Grenzen, die Hausregel-Schalter und `serverAddress` (die SFS-Adresse samt Port je Tisch).
|
||||
|
||||
Damit haengt die **Auswahl** nicht mehr an einer Ansicht. Reine Funktionen fuer alles,
|
||||
was mit den Daten zu tun ist; der Netzzugriff ist eine duenne Funktion daneben.
|
||||
|
||||
tische(daten) -> Liste der Tische, wie gelesen (nichts umbenannt)
|
||||
zeilen(daten) -> dieselben Tische im Zeilenformat von lobby/auswahl.py (dort wird gewaehlt)
|
||||
server(tisch) -> (host, port) aus serverAddress - die Gegenstelle dieses Tisches
|
||||
holen(...) -> die Antwort des Dienstes (Text)
|
||||
|
||||
Spezifikation: tests/raumliste_spec.py. Beleg: archiv/echt/beispiel-lobby.json (echte Antwort).
|
||||
"""
|
||||
import base64
|
||||
import glob
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
# Derselbe Rand wie in werkzeuge/liste_von_aussen.py: die Domaene wird gespiegelt, die volle
|
||||
# Desktop-Kennung ist Pflicht, ohne Bearer antwortet die Anwendung nicht.
|
||||
DOMAENEN = ("thecloudinfra.com", "educationsacademy.com", "coinpoker.ai",
|
||||
"betagammabox.ai", "viralrespawn.com")
|
||||
UA = ("Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 "
|
||||
"(KHTML, like Gecko) CoinPoker/1.31.0 Chrome/128.0.0.0 Electron/32.0.0 Safari/537.36")
|
||||
IDB = "~/Library/Application Support/CoinPoker/IndexedDB/file__0.indexeddb.leveldb"
|
||||
API_KEY = "AIzaSyCZuzp9ifcCiQxI6CIDZeeY2HIx77-Ump4"
|
||||
ERLAUBT = set(b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~+/=")
|
||||
|
||||
|
||||
def _lauf(rohdaten, praefix):
|
||||
p = praefix.encode()
|
||||
raus, i = [], 0
|
||||
while True:
|
||||
i = rohdaten.find(p, i)
|
||||
if i < 0:
|
||||
return raus
|
||||
j = i
|
||||
while j < len(rohdaten) and rohdaten[j] in ERLAUBT:
|
||||
j += 1
|
||||
raus.append(rohdaten[i:j].decode("ascii"))
|
||||
i = j
|
||||
|
||||
|
||||
def token_aus_client(pfad=None):
|
||||
"""Der juengste noch gueltige Firebase-Token aus der IndexedDB des laufenden Clients."""
|
||||
ordner = os.path.expanduser(pfad or IDB)
|
||||
dateien = sorted(glob.glob(ordner + "/*.log") + glob.glob(ordner + "/*.ldb"),
|
||||
key=os.path.getmtime, reverse=True)
|
||||
bestes = (0, None)
|
||||
for f in dateien:
|
||||
for t in _lauf(open(f, "rb").read(), "eyJhbGciOi"):
|
||||
if t.count(".") != 2:
|
||||
continue
|
||||
p = t.split(".")[1]
|
||||
p += "=" * (-len(p) % 4)
|
||||
try:
|
||||
exp = json.loads(base64.urlsafe_b64decode(p)).get("exp", 0)
|
||||
except Exception:
|
||||
continue
|
||||
if exp > bestes[0]:
|
||||
bestes = (exp, t)
|
||||
return bestes[1]
|
||||
|
||||
|
||||
def holen(token=None, pfad="/get-cash-lobby-list", nutzlast=None):
|
||||
"""Die Antwort des Listing-Dienstes (Text) - ueber die erste Domaene, die antwortet."""
|
||||
token = token or token_aus_client()
|
||||
if not token:
|
||||
return None
|
||||
koerper = json.dumps(nutzlast or {"coinTypeId": [1], "isBombpot": True}).encode()
|
||||
letzter = None
|
||||
for d in DOMAENEN:
|
||||
anfrage = urllib.request.Request(f"https://public-cash-listing.{d}{pfad}", data=koerper,
|
||||
headers={"content-type": "application/json", "user-agent": UA,
|
||||
"accept": "application/json",
|
||||
"authorization": "Bearer " + token})
|
||||
try:
|
||||
return urllib.request.urlopen(anfrage, timeout=25).read().decode()
|
||||
except urllib.error.HTTPError as e:
|
||||
letzter = e.read().decode()[:200]
|
||||
if e.code in (403, 430):
|
||||
continue
|
||||
return letzter
|
||||
except Exception as e:
|
||||
letzter = repr(e)[:120]
|
||||
return letzter
|
||||
|
||||
|
||||
def tische(daten):
|
||||
"""Die Tischdatensaetze aus der verschachtelten Antwort - Reihenfolge wie geliefert.
|
||||
|
||||
Nimmt Text oder schon geladene Daten. Nichts wird umbenannt: was der Dienst nennt, gilt."""
|
||||
if isinstance(daten, (str, bytes)):
|
||||
try:
|
||||
daten = json.loads(daten)
|
||||
except ValueError:
|
||||
return []
|
||||
raus = []
|
||||
|
||||
def geh(knoten):
|
||||
if isinstance(knoten, dict):
|
||||
if "roomName" in knoten and "tableId" in knoten:
|
||||
raus.append(knoten)
|
||||
for v in knoten.values():
|
||||
geh(v)
|
||||
elif isinstance(knoten, list):
|
||||
for v in knoten:
|
||||
geh(v)
|
||||
|
||||
geh(daten.get("data") if isinstance(daten, dict) else daten)
|
||||
return raus
|
||||
|
||||
|
||||
def zeilen(daten):
|
||||
"""Dieselben Tische im Format von `lobby/auswahl.py` - dort faellt die Wahl, hier nur die Form.
|
||||
|
||||
`blinds` und `spieler` werden so geschrieben, wie `auswahl` sie liest ("0.5 / 1", "5/6"):
|
||||
damit gilt fuer die Auswahl dieselbe Quelle und dieselben Regeln wie fuer die Lobby."""
|
||||
raus = []
|
||||
for t in tische(daten):
|
||||
bb, sb = t.get("bigBlind"), t.get("smallBlind")
|
||||
if not bb or not sb:
|
||||
continue
|
||||
raus.append({"id": t.get("tableId"), "name": t.get("roomName"),
|
||||
"blinds": f"{sb:g} / {bb:g}",
|
||||
"spieler": f"{t.get('joinedUserCount', 0)}/{t.get('tableSize') or 6}",
|
||||
"schnitt": t.get("averageStack") or 0})
|
||||
return raus
|
||||
|
||||
|
||||
def server(tisch):
|
||||
"""(host, port) der Gegenstelle dieses Tisches - letztes Feld von `serverAddress`.
|
||||
|
||||
Form: "poker-cash-0.coinpoker.ai:443;HELM_REVERSION1;<uuid>;poker-nlb.coinpoker.ai:7000"."""
|
||||
roh = (tisch or {}).get("serverAddress") or ""
|
||||
letztes = roh.split(";")[-1]
|
||||
if ":" not in letztes:
|
||||
return None
|
||||
host, _, port = letztes.partition(":")
|
||||
return (host, int(port)) if port.isdigit() else None
|
||||
|
||||
|
||||
def mit_regel(alle, feld, wert=True):
|
||||
"""Nur Tische, bei denen ein Hausregel-Schalter so steht - z. B. `mit_regel(t, "isNoLimp")`."""
|
||||
return [t for t in alle if t.get(feld) is wert]
|
||||
|
||||
|
||||
def frisch(text):
|
||||
"""Ist die Antwort brauchbar (kein Sperr-Text, Tische drin)?"""
|
||||
return bool(tische(text))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
text = holen()
|
||||
if not text or not frisch(text):
|
||||
print("keine Liste:", (text or "")[:120])
|
||||
sys.exit(1)
|
||||
for t in sorted(tische(text), key=lambda x: x.get("bigBlind") or 0):
|
||||
s = server(t)
|
||||
print(f"{(s[0] + ':' + str(s[1])) if s else '-':<34} {t.get('roomName')}")
|
||||
@@ -0,0 +1,106 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Die Tischliste aus der API lesen (lesen/raumliste.py) - gegen eine echte Antwort.
|
||||
|
||||
Beleg: `archiv/echt/beispiel-lobby.json` ist eine woertlich gesicherte Antwort des
|
||||
Listing-Dienstes (3 Tische, gekuerzt aus 60). Die Pruefung laeuft damit offline.
|
||||
|
||||
Wichtig ist die Form: `zeilen()` schreibt die Tische so, wie `lobby/auswahl.py` sie liest - dann
|
||||
gilt fuer die Wahl dieselbe Quelle und dieselben Regeln, egal ob die Zeile aus der Lobby oder aus
|
||||
der API kommt.
|
||||
|
||||
python3 tests/raumliste_spec.py -v
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
HIER = os.path.dirname(os.path.abspath(__file__))
|
||||
WURZEL = os.path.dirname(HIER)
|
||||
for p in (WURZEL, os.path.join(WURZEL, "lesen"), os.path.join(WURZEL, "lobby")):
|
||||
if p not in sys.path:
|
||||
sys.path.insert(0, p)
|
||||
|
||||
import auswahl
|
||||
import raumliste
|
||||
|
||||
BELEG = os.path.join(WURZEL, "archiv", "echt", "beispiel-lobby.json")
|
||||
|
||||
|
||||
class Lesen(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.text = open(BELEG, encoding="utf-8").read()
|
||||
|
||||
def test_alle_tische_kommen_heraus(self):
|
||||
self.assertEqual(len(raumliste.tische(self.text)), 3)
|
||||
|
||||
def test_nichts_wird_umbenannt(self):
|
||||
t = raumliste.tische(self.text)[0]
|
||||
self.assertIn("roomName", t)
|
||||
self.assertIn("tableId", t)
|
||||
self.assertIn("serverAddress", t)
|
||||
|
||||
def test_kaputter_text_ist_leer(self):
|
||||
self.assertEqual(raumliste.tische("kein json"), [])
|
||||
self.assertFalse(raumliste.frisch("Sperrtext"))
|
||||
|
||||
def test_ordnung_bleibt_wie_geliefert(self):
|
||||
ids = [t["tableId"] for t in raumliste.tische(self.text)]
|
||||
self.assertEqual(ids[0], json.loads(self.text)["data"][0]["tableId"])
|
||||
|
||||
|
||||
class Form(unittest.TestCase):
|
||||
"""Die Zeilen muessen von `auswahl` gelesen werden koennen - sonst nuetzt die Quelle nichts."""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.zeilen = raumliste.zeilen(open(BELEG, encoding="utf-8").read())
|
||||
|
||||
def test_jede_zeile_hat_die_felder_der_lobby(self):
|
||||
for z in self.zeilen:
|
||||
self.assertEqual(sorted(z), ["blinds", "id", "name", "schnitt", "spieler"])
|
||||
|
||||
def test_auswahl_liest_stakes_und_spieler(self):
|
||||
s = auswahl.stakes_von(self.zeilen[0])
|
||||
self.assertIsNotNone(s)
|
||||
self.assertGreater(s["bb"], 0)
|
||||
sp, plaetze = auswahl.spieler(self.zeilen[0]["spieler"])
|
||||
self.assertIsInstance(sp, int)
|
||||
roh = {t["tableId"]: t for t in raumliste.tische(open(BELEG, encoding="utf-8").read())}
|
||||
self.assertEqual(plaetze, roh[self.zeilen[0]["id"]]["tableSize"]) # Plaetze aus dem Tisch
|
||||
|
||||
def test_ohne_blinds_faellt_die_zeile_raus(self):
|
||||
roh = {"data": [{"roomName": "X", "tableId": 1, "bigBlind": 0, "smallBlind": 0}]}
|
||||
self.assertEqual(raumliste.zeilen(roh), [])
|
||||
|
||||
def test_die_auswahl_arbeitet_darauf(self):
|
||||
"""Gegenprobe: die Wahl laeuft auf API-Zeilen genau wie auf Lobby-Zeilen."""
|
||||
urteil = auswahl.waehlen(self.zeilen, band=(0.001, 1000))
|
||||
self.assertTrue(auswahl.gewaehlte(urteil))
|
||||
|
||||
|
||||
class Gegenstelle(unittest.TestCase):
|
||||
def test_server_aus_der_adresse(self):
|
||||
t = raumliste.tische(open(BELEG, encoding="utf-8").read())[0]
|
||||
host, port = raumliste.server(t)
|
||||
self.assertTrue(host.endswith("coinpoker.ai"))
|
||||
self.assertIsInstance(port, int)
|
||||
self.assertGreater(port, 0)
|
||||
|
||||
def test_ohne_adresse_nichts(self):
|
||||
self.assertIsNone(raumliste.server({}))
|
||||
self.assertIsNone(raumliste.server({"serverAddress": "nur-ein-name"}))
|
||||
|
||||
|
||||
class Regeln(unittest.TestCase):
|
||||
def test_nur_tische_mit_dem_schalter(self):
|
||||
alle = [{"tableId": 1, "isNoLimp": True}, {"tableId": 2, "isNoLimp": False}]
|
||||
self.assertEqual([t["tableId"] for t in raumliste.mit_regel(alle, "isNoLimp")], [1])
|
||||
|
||||
def test_ohne_schalter_leer(self):
|
||||
self.assertEqual(raumliste.mit_regel([{"tableId": 1}], "isRit"), [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user