# -*- coding: utf-8 -*- """Pre-flight classifier for GitHub accounts used as WaveSpeed OAuth donors. WaveSpeed is GitHub-OAuth only, so an account that GitHub refuses to authorize is worthless no matter how many times you retry. Two failure modes dominate and are invisible until the full (captcha-paid) pipeline runs: * ``flagged`` — "This account is flagged, and therefore cannot authorize a third party application". Freshly mass-registered accounts hit this almost immediately; nothing can be done client-side. * ``nosession`` — /login lands without an authenticated session (password changed, device verification required, or the egress IP already burned its GitHub login budget). The authorize URL then redirects to /login. Only ``ready`` accounts deserve a Turnstile solve. Classifying costs one login and one page fetch per account (~5-8 s) and no captcha money. Usage: python ws_classify.py [skip] # appends ready accounts to pool_ready.json, verdicts to classify.log Pool format: JSON list (or JSONL) of {login, password, totp, email, email_pw}. """ import json import os import sys import time import requests HOME = os.path.dirname(os.path.abspath(__file__)) OUT = os.path.join(HOME, "pool_ready.json") SEEN = os.path.join(HOME, "classify_seen.txt") LOG = os.path.join(HOME, "classify.log") UA = ("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 " "(KHTML, like Gecko) Chrome/140.0.0.0 Safari/537.36") CLIENT_ID = os.environ.get("WS_GH_CLIENT_ID", "Ov23liO4t6o6MsNlCsE9") AUTH = ("https://github.com/login/oauth/authorize?client_id=%s" "&redirect_uri=https%%3A%%2F%%2Fwavespeed.ai%%2Fcenter%%2Fdefault%%2Fgithub%%2Fcallback" "&response_type=code" % CLIENT_ID) def log(msg): print(msg, flush=True) with open(LOG, "a", encoding="utf-8") as f: f.write(time.strftime("%H:%M:%S ") + msg + "\n") def gh_login(acc): """Direct (residential) login. Returns (session, verdict).""" s = requests.Session() s.headers.update({"User-Agent": UA, "Accept-Language": "en-US,en;q=0.9"}) r = s.get("https://github.com/login", timeout=45) import re m = re.search(r'name="authenticity_token" value="([^"]+)"', r.text) if not m: return None, "no-csrf" r = s.post("https://github.com/session", data={"authenticity_token": m.group(1), "login": acc["login"], "password": acc["password"], "commit": "Sign in", "return_to": ""}, timeout=45, allow_redirects=True) if "verified-device" in r.url: return None, "verified-device" if "two-factor" in r.url: if not acc.get("totp"): return None, "2fa-no-secret" try: import pyotp except ImportError: return None, "2fa-no-pyotp" m2 = re.search(r'name="authenticity_token" value="([^"]+)"', r.text) r = s.post("https://github.com/sessions/two-factor", data={"authenticity_token": m2.group(1) if m2 else "", "otp": pyotp.TOTP(acc["totp"]).now()}, timeout=45, allow_redirects=True) if "two-factor" in r.url: return None, "2fa-fail" if "github.com/login" in r.url: return None, "login-fail" return s, "ok" def classify(acc): s, verdict = gh_login(acc) if not s: return "login:" + verdict try: r = s.get(AUTH, timeout=45, allow_redirects=True) body = r.text.lower() if "cannot authorize a third party application" in body: return "flagged" if "login/oauth/authorize" in r.url and "authorize" in body: return "ready" if "/login" in r.url: return "nosession" return "other:" + r.url[:60] except Exception as e: # noqa: BLE001 return "authz-err:" + repr(e)[:60] def load_pool(path): txt = open(path, encoding="utf-8", errors="replace").read().strip() if txt.startswith("["): return json.loads(txt) out = [] for line in txt.splitlines(): line = line.strip() if line: try: out.append(json.loads(line)) except Exception: # noqa: BLE001 pass return out def main(): if len(sys.argv) < 2: print(__doc__) return pool = load_pool(sys.argv[1]) limit = int(sys.argv[2]) if len(sys.argv) > 2 else 50 skip = int(sys.argv[3]) if len(sys.argv) > 3 else 0 done = set(open(SEEN).read().split()) if os.path.exists(SEEN) else set() todo = [a for a in pool if a.get("login") and a["login"] not in done] log("pool=%d done=%d todo=%d" % (len(pool), len(done), len(todo))) good = 0 for acc in todo[skip:skip + limit]: verdict = classify(acc) if verdict == "ready": good += 1 with open(OUT, "a", encoding="utf-8") as f: f.write(json.dumps(acc, ensure_ascii=False) + "\n") with open(SEEN, "a") as f: f.write(acc["login"] + "\n") log("%s -> %s" % (acc["login"], verdict)) log("DONE ready=%d of %d" % (good, limit)) if __name__ == "__main__": main()