Files

172 lines
7.9 KiB
Python

import argparse, imaplib, email, json, os, re, subprocess, sys, time
from playwright.sync_api import sync_playwright
GMAIL_USER = "baradok609@gmail.com"
CRED = json.load(open(r"C:/Users/User/tmp/cn_gpt_farm/gmail_donors.json", encoding="utf-8"))
GMAIL_PWD = CRED[GMAIL_USER]
BANK = "C:/Users/User/tmp/framer/bank.jsonl"
def log(m):
print("[%s] %s" % (time.strftime("%H:%M:%S"), m), flush=True)
def mail_token(to_addr, wait=150):
deadline = time.time() + wait
while time.time() < deadline:
try:
M = imaplib.IMAP4_SSL("imap.gmail.com", 993); M.login(GMAIL_USER, GMAIL_PWD)
M.select("INBOX", readonly=True)
typ, ids = M.search(None, 'SUBJECT', '"activation link for Framer"', 'TO', '"%s"' % to_addr)
idl = ids[0].split()
if idl:
typ, msg = M.fetch(idl[-1], '(RFC822)')
m = email.message_from_bytes(msg[0][1]); body = ""
if m.is_multipart():
for part in m.walk():
if part.get_content_type() in ("text/plain", "text/html"):
try:
body += part.get_payload(decode=True).decode(part.get_content_charset() or "utf-8", "replace")
except Exception:
pass
else:
body = (m.get_payload(decode=True) or b"").decode("utf-8", "replace")
mm = re.search(r'https://framer\.com/login#token=([0-9a-f-]{36})', body)
M.logout()
if mm:
return mm.group(1)
M.logout()
except Exception as e:
log("imap err %s" % e)
time.sleep(5)
return None
def click_continue(page):
return page.evaluate("() => { const b=[...document.querySelectorAll('button')].find(x=>(x.innerText||'').trim()==='Continue'); if(b){b.click();return true} return false }")
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--email", required=True)
ap.add_argument("--first", default="Nikita")
ap.add_argument("--last", default="Reform")
ap.add_argument("--port", default="9270")
ap.add_argument("--idx", default="0")
ap.add_argument("--proxy", default="")
a = ap.parse_args()
prof = "C:/Users/User/tmp/framer/prof" + a.port
env = dict(os.environ); env["CTX_CDP_PORT"] = a.port; env["CTX_CHROME_PROF"] = prof
if a.proxy: env["CTX_CHROME_PROXY"] = a.proxy
subprocess.run([sys.executable, "C:/Users/User/tmp/agentrouter/chrome_up.py"], env=env, check=True)
rec = {"email": a.email, "idx": a.idx, "ts": time.strftime("%Y-%m-%dT%H:%M:%S"), "status": "start"}
signup_ok = {"v": False}
try:
with sync_playwright() as p:
br = p.chromium.connect_over_cdp("http://127.0.0.1:%s" % a.port)
ctx = br.contexts[0]
page = ctx.pages[0] if ctx.pages else ctx.new_page()
def on_resp(r):
if "/auth/v3/signup" in r.url and r.status < 400:
signup_ok["v"] = True
page.on("response", on_resp)
page.goto("https://framer.com/", wait_until="domcontentloaded", timeout=90000)
page.wait_for_timeout(3000)
page.goto("https://framer.com/login/", wait_until="domcontentloaded", timeout=90000)
page.wait_for_selector("#email", timeout=60000)
page.wait_for_timeout(5000)
for _ in range(6):
page.fill("#email", a.email)
page.wait_for_timeout(400)
if page.input_value("#email") == a.email:
break
page.wait_for_timeout(1000)
click_continue(page)
got = False
for _ in range(30):
page.wait_for_timeout(1000)
if "activate" in page.url or "check" in page.url:
got = True; break
if not got:
log("no activate page: %s" % page.url)
if not got:
rec["status"] = "signin_fail"
rec["detail"] = page.evaluate("()=>document.body.innerText.slice(0,200)").replace("\n", " ")
else:
tok = mail_token(a.email)
if not tok:
rec["status"] = "no_mail"
else:
rec["token"] = tok
ok_page = False
for _try in range(2):
try:
page.goto("https://framer.com/login#token=%s" % tok, wait_until="domcontentloaded", timeout=60000)
except Exception as e:
log("goto token err %s" % e); continue
for _ in range(28):
page.wait_for_timeout(1000)
try:
if "complete-sign-up" in page.url or page.query_selector("input[placeholder='First name']"):
ok_page = True; break
except Exception:
pass
if ok_page: break
if not ok_page:
rec["status"] = "activate_fail"
rec["detail"] = page.evaluate("()=>document.body.innerText.slice(0,200)").replace("\n", " ")
rec["url"] = page.url
else:
page.fill("input[placeholder='First name']", a.first, timeout=15000)
page.fill("input[placeholder='Last name']", a.last, timeout=15000)
page.wait_for_timeout(900)
for attempt in range(3):
click_continue(page)
for _ in range(20):
page.wait_for_timeout(500)
if signup_ok["v"] or "/projects/" in page.url:
break
if signup_ok["v"] or "/projects/" in page.url:
break
log("retry continue %d" % attempt)
page.wait_for_timeout(1200)
rec["signup_api_ok"] = signup_ok["v"]
rec["url"] = page.url
m = re.search(r'/projects/([A-Za-z0-9]+)', page.url)
rec["project_id"] = m.group(1) if m else None
try:
info = page.evaluate("""async () => {
const r = await fetch('https://api.framer.com/web/users/me', {credentials:'include'});
if(!r.ok) return {err:r.status};
const d = await r.json();
return {id:d.id, name:d.name, email:d.email};
}""")
rec["api"] = info
except Exception as e:
rec["api"] = {"err": str(e)}
rec["cookies"] = [{"name": c["name"], "value": c["value"], "domain": c["domain"]} for c in ctx.cookies()]
if signup_ok["v"] or (rec.get("api") or {}).get("id"):
rec["status"] = "ok"
else:
rec["status"] = "unconfirmed"
except Exception as e:
rec["status"] = rec["status"] if rec["status"] != "start" else "exc"
rec["detail"] = str(e)
with open(BANK, "a", encoding="utf-8") as f:
f.write(json.dumps(rec, ensure_ascii=False) + "\n")
log("%s -> %s %s" % (a.email, rec["status"], rec.get("url") or rec.get("detail") or ""))
# kill this profile's chrome to free resources
try:
import psutil
for pr in psutil.process_iter(["cmdline"]):
cl = " ".join(pr.info.get("cmdline") or [])
if "remote-debugging-port=%s" % a.port in cl:
pr.kill()
except Exception:
pass
if __name__ == "__main__":
main()