souz.ai: TG-OAuth mass registration + pool shim (100 RUB accounts)
This commit is contained in:
@@ -0,0 +1,239 @@
|
||||
"""souz.ai mass registration over Telegram bot OAuth (1 TG account = 1 souz account, 100 RUB bonus)."""
|
||||
import asyncio, json, os, random, sys, time, urllib.request, http.cookiejar
|
||||
|
||||
PROXY_CFG = r"C:\Users\User\.secrets\proxy_pool.json"
|
||||
|
||||
|
||||
def _load_proxies():
|
||||
try:
|
||||
d = json.load(open(PROXY_CFG, encoding="utf-8"))
|
||||
auth = d.get("auth") or ""
|
||||
port = d.get("port") or 8888
|
||||
out = []
|
||||
for h in d.get("hosts") or []:
|
||||
out.append("http://%s@%s:%s" % ((auth + "@") if auth else "", h, port))
|
||||
return out
|
||||
except Exception:
|
||||
return []
|
||||
|
||||
|
||||
PROXIES = _load_proxies()
|
||||
|
||||
|
||||
def pick_proxy():
|
||||
if PROXIES:
|
||||
return random.choice(PROXIES)
|
||||
return ""
|
||||
|
||||
API_ID = int(os.environ.get("TG_API_ID", 23926822))
|
||||
API_HASH = os.environ.get("TG_API_HASH", "f383e16e2f55bc0857291510fd513002")
|
||||
BASE = "https://souz.ai"
|
||||
UA = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) "
|
||||
"Chrome/156.0.0.0 Safari/537.36")
|
||||
HERE = os.environ.get("SOUZ_HOME", os.path.dirname(os.path.abspath(__file__)))
|
||||
BANK = os.environ.get("SOUZ_BANK", os.path.join(HERE, "souz_bank.jsonl"))
|
||||
DEAD = os.path.join(HERE, "souz_dead.txt")
|
||||
LOG = open(os.path.join(HERE, "souz_wave.log"), "a", encoding="utf-8", buffering=1)
|
||||
|
||||
|
||||
def log(*a):
|
||||
LOG.write(time.strftime("%H:%M:%S ") + " ".join(str(x) for x in a) + "\n")
|
||||
|
||||
|
||||
class Api:
|
||||
def __init__(self):
|
||||
self.jar = http.cookiejar.CookieJar()
|
||||
self.op = None
|
||||
|
||||
def _build(self, px):
|
||||
self.op = urllib.request.build_opener(
|
||||
urllib.request.ProxyHandler({'http': px, 'https': px}) if px else urllib.request.build_opener().handlers[0] and urllib.request.ProxyHandler({}),
|
||||
urllib.request.HTTPCookieProcessor(self.jar))
|
||||
|
||||
def req(self, path, method="GET", body=None, navigate=False, follow=True, tries=3, timeout=30):
|
||||
last = None
|
||||
for attempt in range(tries):
|
||||
px = pick_proxy()
|
||||
handlers = [urllib.request.HTTPCookieProcessor(self.jar)]
|
||||
if px:
|
||||
handlers.append(urllib.request.ProxyHandler({'http': px, 'https': px}))
|
||||
else:
|
||||
handlers.append(urllib.request.ProxyHandler({}))
|
||||
if not follow:
|
||||
class NoRedir(urllib.request.HTTPRedirectHandler):
|
||||
def redirect_request(self, *a, **k):
|
||||
return None
|
||||
handlers.append(NoRedir)
|
||||
op = urllib.request.build_opener(*handlers)
|
||||
if navigate:
|
||||
h = {"User-Agent": UA, "Accept-Language": "ru-RU,ru;q=0.9,en;q=0.8",
|
||||
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8",
|
||||
"Sec-Fetch-Site": "none", "Sec-Fetch-Mode": "navigate", "Sec-Fetch-Dest": "document",
|
||||
"Sec-Fetch-User": "?1", "Upgrade-Insecure-Requests": "1"}
|
||||
else:
|
||||
h = {"User-Agent": UA, "Accept": "application/json, text/plain, */*",
|
||||
"Accept-Language": "ru-RU,ru;q=0.9", "Referer": BASE + "/login", "Origin": BASE,
|
||||
"Sec-Fetch-Site": "same-origin", "Sec-Fetch-Mode": "cors", "Sec-Fetch-Dest": "empty"}
|
||||
data = None
|
||||
if body is not None:
|
||||
data = json.dumps(body).encode()
|
||||
h["Content-Type"] = "application/json"
|
||||
try:
|
||||
r = op.open(urllib.request.Request(BASE + path, data=data, headers=h, method=method), timeout=timeout)
|
||||
return r.status, r.read()
|
||||
except urllib.error.HTTPError as e:
|
||||
return e.code, e.read()
|
||||
except Exception as e:
|
||||
last = type(e).__name__
|
||||
time.sleep(1.5)
|
||||
return -1, str(last).encode()
|
||||
|
||||
def j(self, path, method="GET", body=None, **kw):
|
||||
c, b = self.req(path, method, body, **kw)
|
||||
try:
|
||||
return c, json.loads(b)
|
||||
except Exception:
|
||||
return c, {"_raw": b.decode("utf-8", "replace")[:150]}
|
||||
|
||||
def cookies(self):
|
||||
return {ck.name: ck.value for ck in self.jar}
|
||||
|
||||
|
||||
async def tg_confirm(session_path, code):
|
||||
from telethon import TelegramClient
|
||||
from telethon.tl.functions.messages import StartBotRequest
|
||||
cl = TelegramClient(session_path, API_ID, API_HASH, device_model="SM-G991B", system_version="13",
|
||||
app_version="10.2.0", lang_code="ru", system_lang_code="ru")
|
||||
try:
|
||||
await cl.connect()
|
||||
if not await cl.is_user_authorized():
|
||||
return {"err": "not_authorized"}
|
||||
me = await cl.get_me()
|
||||
await cl(StartBotRequest(bot="souz_ai_bot", peer="souz_ai_bot", start_param=code))
|
||||
await asyncio.sleep(2.5)
|
||||
return {"tg_id": me.id, "tg_user": me.username,
|
||||
"name": ((me.first_name or "") + " " + (me.last_name or "")).strip()}
|
||||
except Exception as e:
|
||||
return {"err": "tg:%s" % type(e).__name__}
|
||||
finally:
|
||||
try:
|
||||
await cl.disconnect()
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def register(session_path, poll_sec=40):
|
||||
api = Api()
|
||||
out = {"session": session_path}
|
||||
c, b = api.req("/", navigate=True)
|
||||
if c != 200:
|
||||
out["err"] = "visit_%s" % c
|
||||
return out
|
||||
st = None
|
||||
for attempt in range(4):
|
||||
c, st = api.j("/v1/auth/telegram/start?next=%2Foverview")
|
||||
if c == 200 and isinstance(st, dict) and "code" in st:
|
||||
break
|
||||
if c == 429:
|
||||
time.sleep(8 * (attempt + 1))
|
||||
continue
|
||||
break
|
||||
if not (c == 200 and isinstance(st, dict) and "code" in st):
|
||||
out["err"] = "start_%s" % c
|
||||
return out
|
||||
code = st["code"]
|
||||
info = asyncio.run(tg_confirm(session_path, code))
|
||||
out["tg"] = info
|
||||
if "err" in info:
|
||||
out["err"] = info["err"]
|
||||
return out
|
||||
status = None
|
||||
for _ in range(int(poll_sec / 2)):
|
||||
c, s = api.j("/v1/auth/telegram/poll?code=" + code)
|
||||
if isinstance(s, dict) and s.get("status") not in (None, "pending"):
|
||||
status = s.get("status")
|
||||
break
|
||||
time.sleep(2)
|
||||
if status is None:
|
||||
out["err"] = "poll_timeout"
|
||||
return out
|
||||
c, b = api.req("/v1/auth/telegram/complete?code=" + code, navigate=True, follow=False)
|
||||
out["complete"] = c
|
||||
if "client_session" not in api.cookies():
|
||||
out["err"] = "no_session_%s" % c
|
||||
return out
|
||||
c, me = api.j("/v1/auth/me")
|
||||
out["me"] = me
|
||||
c, bal = api.j("/v1/balance")
|
||||
out["balance"] = bal
|
||||
c, k = api.j("/v1/keys", "POST", {"name": "main"})
|
||||
out["key"] = k
|
||||
out["ok"] = True
|
||||
out["ts"] = int(time.time())
|
||||
return out
|
||||
|
||||
|
||||
def load_sessions():
|
||||
seen, out = set(), []
|
||||
for fn in ("pool_conv.json", "pool_all2.json", "pool_live9.json"):
|
||||
p = os.path.join(r"C:\Users\User\tmp\tg_chat_grow", fn)
|
||||
if not os.path.exists(p):
|
||||
continue
|
||||
try:
|
||||
data = json.load(open(p, encoding="utf-8"))
|
||||
except Exception:
|
||||
continue
|
||||
for s in data:
|
||||
if isinstance(s, dict):
|
||||
s = s.get("path") or s.get("session")
|
||||
if not s or s in seen:
|
||||
continue
|
||||
if not os.path.exists(s):
|
||||
continue
|
||||
seen.add(s)
|
||||
out.append(s)
|
||||
return out
|
||||
|
||||
|
||||
def main():
|
||||
limit = int(sys.argv[1]) if len(sys.argv) > 1 else 20
|
||||
sessions = load_sessions()
|
||||
done = set()
|
||||
if os.path.exists(BANK):
|
||||
for line in open(BANK, encoding="utf-8"):
|
||||
try:
|
||||
d = json.loads(line)
|
||||
done.add(d.get("session"))
|
||||
except Exception:
|
||||
pass
|
||||
log("sessions=%d done=%d limit=%d" % (len(sessions), len(done), limit))
|
||||
n = 0
|
||||
ok = 0
|
||||
for sp in sessions:
|
||||
if n >= limit:
|
||||
break
|
||||
if sp in done:
|
||||
continue
|
||||
t0 = time.time()
|
||||
try:
|
||||
res = register(sp)
|
||||
except Exception as e:
|
||||
res = {"session": sp, "err": "exc:%s" % type(e).__name__}
|
||||
res["elapsed"] = round(time.time() - t0, 1)
|
||||
with open(BANK, "a", encoding="utf-8") as f:
|
||||
f.write(json.dumps(res, ensure_ascii=False) + "\n")
|
||||
n += 1
|
||||
if res.get("ok"):
|
||||
ok += 1
|
||||
bal = (res.get("balance") or {}).get("available_micro")
|
||||
log("OK %s tg=%s bal=%s %.0fs" % (os.path.basename(sp)[:22], res["tg"].get("tg_id"), bal, res["elapsed"]))
|
||||
else:
|
||||
log("FAIL %s %s" % (os.path.basename(sp)[:22], res.get("err")))
|
||||
if res.get("err") in ("not_authorized", "tg:AuthKeyUnregistered", "tg:AuthKeyDuplicated"):
|
||||
with open(DEAD, "a", encoding="utf-8") as f:
|
||||
f.write(sp + "\n")
|
||||
log("batch done ok=%d/%d" % (ok, n))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user