Files
contextdev-autoreg/fin_one.py
T

90 lines
4.0 KiB
Python

import json, os, re, subprocess, sys, time
import requests
from playwright.sync_api import sync_playwright
BASE = os.path.dirname(os.path.abspath(__file__))
CTOK = sys.argv[1]
UCODE = sys.argv[2]
MAIL = sys.argv[3] if len(sys.argv) > 3 else ""
PORT = os.environ.get("CTX_CDP_PORT", "9351")
CDP = "http://127.0.0.1:%s" % PORT
PROF = os.environ.get("CTX_CHROME_PROF", BASE + r"\chrome_fin1")
PROXY = os.environ.get("CTX_CHROME_PROXY", "")
IDPXY = {"http": os.environ.get("CTX_ID_PROXY", "http://127.0.0.1:8899"), "https": os.environ.get("CTX_ID_PROXY", "http://127.0.0.1:8899")}
VURI = "https://www.context.dev/claim?claim_attempt_token=" + CTOK
def log(*a, **kw):
kw.setdefault("flush", True); print(*a, **kw)
def txt(pg, n=300):
try: return pg.inner_text("body")[:n]
except Exception: return ""
def click(pg, rx):
for kind in ("button", "link"):
try:
el = pg.get_by_role(kind, name=re.compile(rx, re.I)).first
if el.count() and el.is_visible(): el.click(); return True
except Exception: pass
return False
if MAIL:
try:
used = set(json.load(open(os.path.join(BASE, "t_used.json"))))
except Exception:
used = set()
used.add(MAIL); json.dump(sorted(used), open(os.path.join(BASE, "t_used.json"), "w"))
env2 = dict(os.environ); env2.update({"CTX_CDP_PORT": PORT, "CTX_CHROME_PROF": PROF, "CTX_CHROME_PROXY": PROXY})
subprocess.run([sys.executable, os.path.join(BASE, "chrome_up.py")], check=False, env=env2)
time.sleep(3)
with sync_playwright() as p:
b = p.chromium.connect_over_cdp(CDP, timeout=90000)
ctx = b.contexts[0]
pg = ctx.new_page(); pg.set_default_timeout(50000)
pg.goto(VURI, timeout=90000, wait_until="domcontentloaded")
time.sleep(8)
t = txt(pg, 300); log("page:", t[:160].replace("\n", " "))
if "verified my email" in t:
click(pg, "verified my email"); time.sleep(9)
t = txt(pg, 250); log("after ack:", t[:140].replace("\n", " "))
ins = pg.locator("input[type=text], input[inputmode=numeric], input[autocomplete=one-time-code]")
if ins.count() >= 6:
for i in range(6): ins.nth(i).fill(UCODE[i])
time.sleep(1)
click(pg, "confirm setup|^confirm$|authorize|continue|finish"); time.sleep(10)
log("after code:", txt(pg, 220).replace("\n", " "), "|", pg.url[:80])
elif ins.count():
ins.first.fill(UCODE); time.sleep(1)
click(pg, "confirm setup|^confirm$|authorize|continue|finish"); time.sleep(10)
log("after code1:", txt(pg, 220).replace("\n", " "), "|", pg.url[:80])
pg.screenshot(path=os.path.join(BASE, "fin_one.png"))
pg.close()
j = {}
for att in range(5):
px = IDPXY if att % 2 == 0 else {"http": os.environ.get("CTX_ID_PROXY2", "http://127.0.0.1:8899"), "https": os.environ.get("CTX_ID_PROXY2", "http://127.0.0.1:8899")}
try:
r = requests.post("https://www.context.dev/oauth2/token",
data={"grant_type": "urn:workos:agent-auth:grant-type:claim", "claim_token": CTOK},
timeout=60, proxies=px)
log("token:", r.status_code, r.text[:160])
if r.text.strip().startswith("{"): j = r.json()
if "access_token" in j or j.get("error") not in (None,): break
except Exception as e:
log("token err", type(e).__name__)
time.sleep(6)
if "access_token" in j:
k = j["access_token"]
log("KEY len", len(k), "gift", j.get("signup_gift_credits"))
u = requests.get("https://api.context.dev/v1/org/logs", headers={"Authorization": "Bearer " + k},
timeout=30, proxies=IDPXY)
log("logs:", u.status_code, u.text[:300])
with open(os.path.join(BASE, "bank.jsonl"), "a") as f:
f.write(json.dumps({"email": MAIL, "tag": "t-online", "key": k, "ts": time.time(),
"claim_token": CTOK, "gift": j.get("signup_gift_credits"), "dead": False}) + "\n")
log("SAVED")
else:
log("NO KEY")