Files
minara-autoreg/farm_parallel.py
T

117 lines
4.0 KiB
Python

#!/usr/bin/env python3
"""Minara parallel farm: N workers register accounts via rotating IPv6 proxies.
usage: python farm_parallel.py <count> [workers]
Writes: bank.jsonl (tokens), pool.jsonl (queue), farm_done.txt (processed emails)
"""
import json, os, random, sys, threading, time
from concurrent.futures import ThreadPoolExecutor, as_completed
try:
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
sys.stderr.reconfigure(encoding="utf-8", errors="replace")
except Exception:
pass
HERE = os.environ.get("MINARA_HOME") or os.path.dirname(os.path.abspath(__file__))
sys.path.insert(0, HERE)
from core import register, BANK
POOL = os.environ.get("MINARA_POOL") or (HERE + "/pool.jsonl")
DONE = HERE + "/farm_done.txt"
LOCK = threading.Lock()
DOMAINS = [d for d in os.environ.get(
"MINARA_DOMAINS",
"rambler.ru,bfirstmail.com,singnet.com.sg,topnet.tn,mail.tmwlsw.com,ldsubmissions.com"
).split(",") if d]
def build_pool():
if os.path.exists(POOL) and os.path.getsize(POOL) > 0:
return
done = set()
if os.path.exists(BANK):
for l in open(BANK, encoding="utf8"):
try:
done.add(json.loads(l)["email"].lower())
except Exception:
pass
rows, seen = [], set(done)
for dom in DOMAINS:
p = os.path.join(os.environ.get("MINARA_LIVE_DIR", "live"), "live_%s.txt" % dom)
if not os.path.exists(p):
print("no pool file for", dom, flush=True)
continue
for line in open(p, encoding="utf8", errors="ignore"):
line = line.strip()
if "@" + dom not in line:
continue
em, _, pw = line.partition(":")
em = em.strip().lower()
pw = pw.strip()
if not pw or em in seen:
continue
seen.add(em)
rows.append({"email": em, "pw": pw, "dom": dom})
random.shuffle(rows)
with open(POOL, "w", encoding="utf8") as fh:
for r in rows:
fh.write(json.dumps(r, ensure_ascii=False) + "\n")
print("pool built:", len(rows), flush=True)
def take(n):
got = []
with LOCK:
with open(POOL, encoding="utf8") as fh:
lines = fh.readlines()
rest = []
for l in lines:
if not l.strip():
continue
try:
r = json.loads(l)
except Exception:
continue
if len(got) < n and (not DOMAINS or r.get("dom") in DOMAINS):
got.append(r)
else:
rest.append(l)
with open(POOL, "w", encoding="utf8") as fh:
fh.writelines(rest)
return got
def worker(row):
try:
rec = register(row["email"], row["pw"], row["dom"])
except Exception as e:
rec = {"email": row["email"], "ok": False, "stage": "exception", "err": str(e)[:150]}
with LOCK:
with open(DONE, "a", encoding="utf8") as fh:
fh.write("%s\t%s\t%s\n" % (row["email"], "ok" if rec.get("ok") else rec.get("stage"), int(time.time())))
tag = "OK " if rec.get("ok") else "FAIL"
try:
msg = rec.get("resp") or rec.get("err") or ""
if not isinstance(msg, str):
msg = json.dumps(msg, ensure_ascii=False, default=str)
print(tag, row["email"], rec.get("stage") or "", "" if rec.get("ok") else msg[:90], flush=True)
except Exception:
print(tag, row.get("email", "?"), "print-error", flush=True)
return rec
if __name__ == "__main__":
count = int(sys.argv[1]) if len(sys.argv) > 1 else 20
workers = int(sys.argv[2]) if len(sys.argv) > 2 else 5
build_pool()
rows = take(count)
print("batch:", len(rows), "workers:", workers, flush=True)
ok = 0
with ThreadPoolExecutor(max_workers=workers) as ex:
futs = [ex.submit(worker, r) for r in rows]
for f in as_completed(futs):
if f.result().get("ok"):
ok += 1
print("DONE ok=%d/%d" % (ok, len(rows)), flush=True)