feat: per-account browser, $2 starter-credit claim, claim_all, tavily hunt probe

This commit is contained in:
reform
2026-11-11 21:38:00 +02:00
parent 5cdc4c4a82
commit 21c42f016a
3 changed files with 288 additions and 16 deletions
+72 -16
View File
@@ -86,9 +86,8 @@ def first_name_from(mail):
return base[:12] or "User"
def run_one(br, mail, imap_pass, bank_path):
def run_one(mail, imap_pass, bank_path):
t0 = time.time()
password = gen_password()
try:
for line in open(bank_path, encoding="utf-8"):
rec = json.loads(line)
@@ -97,8 +96,27 @@ def run_one(br, mail, imap_pass, bank_path):
break
except Exception:
pass
ctx = br.new_context(viewport={"width": 1280, "height": 900}, locale="de-DE")
pg = ctx.new_page()
with sync_playwright() as _p:
br = _p.chromium.launch(executable_path=CHROME, headless=False,
args=["--disable-blink-features=AutomationControlled", "--no-first-run",
"--disable-dev-shm-usage", "--disable-gpu",
"--disable-background-timer-throttling", "--window-size=1100,800"])
ctx = br.new_context(viewport={"width": 1280, "height": 900}, locale="de-DE")
pg = ctx.new_page()
return _drive(br, ctx, pg, mail, imap_pass, bank_path, t0)
def _drive(br, ctx, pg, mail, imap_pass, bank_path, t0):
password = gen_password()
try:
import json as _j
for line in open(bank_path, encoding="utf-8"):
rec = _j.loads(line)
if rec.get("email", "").lower() == mail.lower() and rec.get("password"):
password = rec["password"]
break
except Exception:
pass
pg.set_default_timeout(25000)
res = {"email": mail, "imap_pass": imap_pass, "password": password, "ok": False, "stage": "start"}
try:
@@ -226,8 +244,42 @@ def run_one(br, mail, imap_pass, bank_path):
res.update(stage="key", err="no ck_ token")
log(" FAIL no key")
return res
# claim $2 starter credit (Instant calls stay paused without it)
credit = None
try:
orgs = set()
def grab(req):
if ("starterCreditStatus" in req.url or "wallet" in req.url
or "orgId" in req.url):
for m in re.findall(r"ok_[A-Za-z0-9]{6,}", req.url):
orgs.add(m)
pg.on("request", grab)
pg.goto(f"{DASH}/{ws_name}/~/connect/team/budget", wait_until="domcontentloaded")
pg.wait_for_timeout(4500)
if not orgs:
pg.goto(f"{DASH}/{ws_name}/~/connect", wait_until="domcontentloaded")
pg.wait_for_timeout(3500)
cand = sorted(orgs)
log(" orgId candidates:", len(cand))
cr = ""
for org in cand:
cr = pg.evaluate("""async (org) => {
const res = await fetch('/api/trpc/consumer.wallet.claimStarterCredit?batch=1', {
method:'POST', headers:{'content-type':'application/json','x-trpc-source':'nextjs'},
body: JSON.stringify({0:{json:{orgId:org}}}), credentials:'include'});
return res.status + '|' + (await res.text()).slice(0,200);
}""", org)
log(" claim", org, ":", cr[:100])
if "does not have access" in cr:
continue
break
if '"status":"granted"' in cr or "already" in cr.lower():
credit = 2
except Exception as e:
log(" claim err:", str(e)[:90])
res.update(ok=True, stage="done", api_key=tok["v"], workspace=ws_name,
elapsed=round(time.time() - t0, 1), ts=int(time.time()))
credit_usd=credit, elapsed=round(time.time() - t0, 1), ts=int(time.time()))
log(" OK key:", tok["v"][:10] + "..." + tok["v"][-4:], "ws:", ws_name)
except Exception as e:
res.update(stage="exc", err=str(e)[:160])
@@ -237,6 +289,10 @@ def run_one(br, mail, imap_pass, bank_path):
ctx.close()
except Exception:
pass
try:
br.close()
except Exception:
pass
with open(bank_path, "a", encoding="utf-8") as f:
f.write(json.dumps(res, ensure_ascii=False) + "\n")
return res
@@ -254,17 +310,17 @@ def main():
todo = lines[a.start:a.start + a.count]
log("wave:", len(todo), "accounts from idx", a.start)
ok = 0
with sync_playwright() as p:
br = p.chromium.launch(executable_path=CHROME, headless=False,
args=["--disable-blink-features=AutomationControlled", "--no-first-run"])
for n, line in enumerate(todo):
mail, imap_pass = line.split(":", 1)
log(f"--- [{a.start + n}] {mail}")
r = run_one(br, mail, imap_pass, a.bank)
if r.get("ok"):
ok += 1
time.sleep(a.pause)
br.close()
for n, line in enumerate(todo):
mail, imap_pass = line.split(":", 1)
log(f"--- [{a.start + n}] {mail}")
try:
r = run_one(mail, imap_pass, a.bank)
except Exception as e:
log(" browser died:", str(e)[:80])
r = {"ok": False}
if r.get("ok"):
ok += 1
time.sleep(a.pause)
log("WAVE DONE ok=%d/%d" % (ok, len(todo)))