Files

98 lines
3.4 KiB
Python

"""Stage A: bulk FreeModel registration (HTTP only) -> fm_pending.jsonl"""
import json, os, random, re, sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
import fm_lib as L
HERE = L.HERE
PEND = os.path.join(HERE, "fm_pending.jsonl")
USED = os.path.join(HERE, "used_emails.txt")
TGGONE = os.path.join(HERE, "tg_used.txt")
BLOCK = os.path.join(HERE, "blocked_domains.txt")
MAILBANK = __import__('os').environ.get('FM_MAILBANK','mailbank.jsonl') # r""
def lines(p):
return [x.strip() for x in open(p, encoding="utf-8", errors="replace") if x.strip()] if os.path.exists(p) else []
def add(p, v):
with open(p, "a", encoding="utf-8") as f:
f.write(str(v) + "\n")
def pxpool():
return [x.strip() for x in open(os.path.join(HERE, "px_all.txt"), encoding="utf-8") if x.strip()]
def tgpool():
pool = {}
for f in ("tg_ok_uniq.json", "tg_scan_uniq.json"):
fp = os.path.join(HERE, f)
if os.path.exists(fp):
pool.update(json.load(open(fp)))
return pool
def emails(n):
import namegen
used = set(lines(USED))
out = []
guard = 0
while len(out) < n and guard < n * 40:
guard += 1
e = namegen.gmail()
if e in used or e in out:
continue
out.append(e)
return out
def main(n):
pend = [json.loads(l) for l in open(PEND, encoding="utf-8")] if os.path.exists(PEND) else []
have = {p["email"] for p in pend} | set(lines(USED))
tgs = [(u, p) for u, p in tgpool().items() if u not in set(lines(TGGONE)) and u not in {x.get("tg_uid") for x in pend}]
random.shuffle(tgs)
pxs = pxpool()
ok = 0
for email in emails(n):
if email in have or not tgs:
continue
tg_uid, tg_path = tgs.pop()
pw = "Fm_" + "".join(random.choices("abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789", k=12))
px = random.choice(pxs)
cj = os.path.join(HERE, "cookies", "c%s.json" % tg_uid)
s = L.Sess(cj, proxy=px)
try:
reg = L.register(s, email, pw)
except Exception as e:
print(json.dumps({"email": email, "exc": str(e)[:80]}), flush=True)
continue
add(USED, email)
res = {"email": email, "tg_uid": tg_uid, "tg_path": tg_path, "px": px,
"reg": {k: reg.get(k) for k in ("stage", "code", "loc")}}
if reg.get("code") == 302 and reg.get("loc") == "/dashboard":
s.s.proxies = {}
st, h, _ = s.get("/dashboard")
m = re.search(r"verify_fm_\d+_[a-f0-9]+", h or "")
if m:
res.update({"password": pw, "start": m.group(0), "state": "pending"})
with open(PEND, "a", encoding="utf-8") as f:
f.write(json.dumps(res, ensure_ascii=False) + "\n")
add(TGGONE, tg_uid)
ok += 1
elif reg.get("code") == 302:
st, h, _ = s.get("/register")
t = re.sub(r"\s+", " ", re.sub(r"<[^>]+>", " ", h or ""))
i = t.find("Sign up with Google")
snippet = t[max(0, i - 200):i][-200:]
res["err"] = snippet
if "paused because of unusual activity" in (h or ""):
dom = email.split("@")[-1].lower()
add(BLOCK, dom)
print(json.dumps(res, ensure_ascii=False)[:300], flush=True)
print("registered", ok, flush=True)
if __name__ == "__main__":
main(int(sys.argv[1]) if len(sys.argv) > 1 else 8)