"""Login existing Composio accounts and claim the $2 starter credit (Instant unblock). Usage: python claim_all.py [--limit N] [--only-missing] Reads bank/accounts.jsonl, logs in with stored password, resolves orgId, calls consumer.wallet.claimStarterCredit, writes credit_usd back to the bank. """ import argparse import json import os import re import sys import time from playwright.sync_api import sync_playwright OUT = "C:/Users/User/tmp/composio" BANK = OUT + "/bank/accounts.jsonl" CHROME = "C:/Program Files/Google/Chrome/Application/chrome.exe" if not os.path.exists(CHROME): CHROME = os.path.expandvars(r"%LOCALAPPDATA%\Google\Chrome\Application\chrome.exe") DASH = "https://dashboard.composio.dev" ENTRY = DASH + "/f/~/connect/clients" def log(*a): print(*a, flush=True) def load_bank(): out = [] for line in open(BANK, encoding="utf-8"): line = line.strip() if line: out.append(json.loads(line)) return out def save_bank(recs): with open(BANK, "w", encoding="utf-8") as f: for r in recs: f.write(json.dumps(r, ensure_ascii=False) + "\n") def claim_one(rec): mail = rec["email"] pw = rec.get("password") if not pw: return "no-password" with sync_playwright() as p: br = p.chromium.launch(executable_path=CHROME, headless=False, args=["--disable-blink-features=AutomationControlled", "--no-first-run"]) ctx = br.new_context(viewport={"width": 1280, "height": 900}, locale="de-DE") pg = ctx.new_page() pg.set_default_timeout(25000) orgs = set() def _grab(r): if "starterCreditStatus" in r.url or "wallet" in r.url or "orgId" in r.url: orgs.update(re.findall(r"ok_[A-Za-z0-9]{6,}", r.url)) pg.on("request", _grab) try: pg.goto(ENTRY, wait_until="domcontentloaded") pg.wait_for_timeout(3500) if pg.locator('input[name="email"]').count() == 0: return "no-login-form" pg.fill('input[name="email"]', mail) pg.keyboard.press("Enter") pg.wait_for_timeout(4500) if pg.locator('input[name="password"]').count() == 0: return f"no-password-field {pg.url[:60]}" pg.fill('input[name="password"]', pw) pg.keyboard.press("Enter") pg.wait_for_timeout(6000) if "passkey" in pg.url and pg.locator('button[name="intent"][value="skip"]').count(): pg.locator('button[name="intent"][value="skip"]').first.click(timeout=8000) pg.wait_for_timeout(5000) if "dashboard.composio.dev" not in pg.url: return f"stuck {pg.url[:70]}" ws = re.match(r"https://dashboard\.composio\.dev/([^/]+)/", pg.url + "/") ws_name = ws.group(1) if ws else "" pg.goto(f"{DASH}/{ws_name}/~/connect/team/budget", wait_until="domcontentloaded") pg.wait_for_timeout(4500) if not orgs: pg.wait_for_timeout(3000) org_list = sorted(orgs) if not org_list: return "no-orgid" org = org_list[0] r = "" for org in org_list: r = 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,160); }""", org) log(" claim", org, ":", r[:90]) if "does not have access" in r: continue break if '"status":"granted"' in r: return "granted" if "already" in r.lower() or "claimed" in r.lower(): return "already" return "refused" except Exception as e: return "exc " + str(e)[:60] finally: try: ctx.close() except Exception: pass try: br.close() except Exception: pass def main(): ap = argparse.ArgumentParser() ap.add_argument("--limit", type=int, default=100) ap.add_argument("--only-missing", action="store_true", default=True) a = ap.parse_args() recs = load_bank() targets = [r for r in recs if r.get("ok") and not r.get("credit_usd")][:a.limit] log("targets:", len(targets)) done = 0 for i, rec in enumerate(targets): log(f"[{i+1}/{len(targets)}] {rec['email']}") st = claim_one(rec) log(" ->", st) if st in ("granted", "already"): rec["credit_usd"] = 2 done += 1 save_bank(recs) time.sleep(5) log("claimed:", done) main()