Files
framer-autoreg/framer_ton.py
T

182 lines
8.4 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=180):
"""Read Framer activation link through t-online IMAP on the VPS."""
import subprocess as sp
creds = {}
for line in open(r"C:/Users/User/Desktop/avtoreg/working_mails.txt", encoding="utf-8", errors="replace"):
line = line.strip()
if not line or line.startswith("#") or ":" not in line:
continue
u, p = line.split(":", 1)
creds[u.lower()] = p
pwd = creds.get(to_addr.lower())
if not pwd:
log("no creds for %s" % to_addr); return None
try:
r = sp.run(["ssh", "-o", "BatchMode=yes", "-o", "StrictHostKeyChecking=no",
"root@93.88.206.29", "python3 /root/tonline_read.py '%s' '%s' %d" % (to_addr, pwd, wait)],
capture_output=True, text=True, timeout=wait + 60)
out = (r.stdout or "").strip().splitlines()
for line in out:
if len(line) == 36 and line.count("-") == 4:
return line
log("reader said: %s" % (out[-1] if out else r.stderr[:120]))
except Exception as e:
log("ssh mail err %s" % e)
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()
su_info = {"status": None, "body": ""}
def on_resp(r):
if "/auth/v3/signup" in r.url:
su_info["status"] = r.status
try: su_info["body"] = r.text()[:220]
except Exception: pass
if 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):
if attempt == 2:
try:
page.click("button[type=submit]", force=True, timeout=6000)
except Exception as _e:
log("submit click err %s" % _e)
else:
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["signup_status"] = su_info["status"]
rec["signup_body"] = su_info["body"]
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()