47 lines
2.5 KiB
Python
47 lines
2.5 KiB
Python
"""Composio Exa Instant: search -> contents -> key regex."""
|
|
import json, re, subprocess, sys, time
|
|
KEY = open("ck_live.txt").read().strip() if __import__("os").path.exists("ck_live.txt") else None
|
|
if not KEY:
|
|
for l in open("bank/accounts.jsonl", encoding="utf-8"):
|
|
r = json.loads(l)
|
|
if r.get("ok") and r.get("api_key"):
|
|
KEY = r["api_key"]; break
|
|
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,}|xoxb-[0-9]{8,}-[A-Za-z0-9\-]{10,}|ck_live_[A-Za-z0-9]{16,}|sk-[A-Za-z0-9]{32,})")
|
|
def mcp(name, args, timeout=150):
|
|
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]}
|
|
d = json.loads(m.group(1))
|
|
t = d["result"]["content"][0]["text"]
|
|
try: return json.loads(t)
|
|
except Exception: return {"raw": t[:400]}
|
|
def run(query, n=8):
|
|
r = mcp("COMPOSIO_MULTI_EXECUTE_TOOL", {"tools":[{"tool_slug":"EXA_SEARCH","arguments":{"query":query,"numResults":n}}]})
|
|
body = json.dumps(r, ensure_ascii=False)
|
|
urls = re.findall(r'"url":\s*"(https?://[^"]+)"', body) or re.findall(r'"id":\s*"(https?://[^"]+)"', body)
|
|
urls = list(dict.fromkeys(urls))[:n]
|
|
print(f"[search] {query[:50]} -> {len(urls)} urls")
|
|
if not urls:
|
|
print(" raw:", body[:300])
|
|
if not urls: return []
|
|
c = mcp("COMPOSIO_MULTI_EXECUTE_TOOL", {"tools":[{"tool_slug":"EXA_GET_CONTENTS_ACTION","arguments":{"urls":urls,"text":True}}]}, timeout=180)
|
|
cbody = json.dumps(c, ensure_ascii=False)
|
|
keys = list(dict.fromkeys(PAT.findall(cbody)))
|
|
print(f"[contents] size={len(cbody)} keys={len(keys)}")
|
|
return keys, urls
|
|
if __name__ == "__main__":
|
|
qs = sys.argv[1:] or ["zapier api key leaked gist sk-"]
|
|
allkeys = {}
|
|
for q in qs:
|
|
res = run(q)
|
|
if res:
|
|
keys, urls = res
|
|
for k in keys: allkeys[k] = urls[0] if urls else ""
|
|
time.sleep(2)
|
|
print("TOTAL keys:", len(allkeys))
|
|
for k, u in list(allkeys.items())[:15]: print(" ", k[:34]+"...", "|", u[:60])
|
|
json.dump(allkeys, open("parsed_keys.json","w",encoding="utf-8"), indent=1)
|