Files
minara-autoreg/flow.py
T

96 lines
3.7 KiB
Python

#!/usr/bin/env python3
"""Minara auto-reg: reCAPTCHA v2 -> email code -> verify with invite code."""
import base64, email as emaillib, imaplib, json, os, random, re, string, sys, time
import requests
API = "https://api.minara.ai"
SITEKEY = "6LfLGJQrAAAAANxZ6T3x1xZfasyW--3cOqldBQEv"
PAGEURL = "https://minara.ai/home?code=UM9Y8P&from=user"
INVITE = "UM9Y8P"
CAPKEY = os.environ.get("TWOCAPTCHA_KEY", "").strip()
HDRS = {
"Content-Type": "application/json",
"Origin": "https://minara.ai",
"Referer": "https://minara.ai/",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36",
}
PX = os.environ.get("MINARA_PROXY", "").strip()
PROXIES = {"http": PX, "https": PX} if PX else None
def solve_captcha(pageurl=PAGEURL, tries=3):
for t in range(tries):
try:
r = requests.post("https://api.2captcha.com/createTask", json={
"clientKey": CAPKEY,
"task": {"type": "RecaptchaV2TaskProxyless", "websiteURL": pageurl,
"websiteKey": SITEKEY}
}, timeout=30).json()
except Exception:
time.sleep(5)
continue
if r.get("errorId"):
print("cap create err", r, flush=True)
time.sleep(5); continue
tid = r["taskId"]
print("captcha task", tid, flush=True)
for _ in range(40):
time.sleep(5)
try:
g = requests.post("https://api.2captcha.com/getTaskResult", json={
"clientKey": CAPKEY, "taskId": tid}, timeout=30).json()
except Exception:
time.sleep(3)
continue
if g.get("status") == "ready":
return g["solution"]["gRecaptchaResponse"]
if g.get("errorId"):
print("cap poll err", g, flush=True); break
return None
def send_code(email):
r = requests.post(f"{API}/auth/email/code", headers=HDRS,
json={"email": email, "captchaToken": solve_captcha()}, timeout=40, proxies=PROXIES)
return r.status_code, r.text
def gmail_code(gm, gp, alias, since_ts, timeout=180):
box = imaplib.IMAP4_SSL("imap.gmail.com")
box.login(gm, gp)
end = time.time() + timeout
while time.time() < end:
box.select("INBOX")
typ, data = box.search(None, 'X-GM-RAW', '"to:%s newer_than:1d"' % alias)
ids = (data[0].split() if data and data[0] else [])[-6:]
for i in reversed(ids):
typ, msg = box.fetch(i, "(RFC822)")
if not msg or not msg[0]:
continue
m = emaillib.message_from_bytes(msg[0][1])
body = ""
if m.is_multipart():
for p in m.walk():
if p.get_content_type() in ("text/plain", "text/html"):
body += p.get_payload(decode=True).decode("utf8", "ignore")
else:
body = m.get_payload(decode=True).decode("utf8", "ignore")
if "minara" not in (m.get("From", "") + body).lower():
continue
codes = re.findall(r"\b(\d{6})\b", body)
if codes:
box.logout()
return codes[0]
time.sleep(6)
box.logout()
return None
def verify(email, code):
r = requests.post(f"{API}/auth/email/verify", headers=HDRS, json={
"email": email, "code": code, "inviteCode": INVITE,
"deviceId": "".join(random.choices(string.hexdigits.lower(), k=32)),
"deviceType": "web",
}, timeout=40, proxies=PROXIES)
return r.status_code, r.text
def me(tok):
r = requests.get(f"{API}/auth/me", headers={**HDRS, "Authorization": "Bearer " + tok}, timeout=30, proxies=PROXIES)
return r.status_code, r.text[:1200]