#!/usr/bin/env python3 """credits_probe.py — проверить кредит-статус всех JWT в пуле. Usage: python tools/credits_probe.py [accounts.jsonl] Читает пул (по строке JSON, поле jwt), для каждого акка: GET /api/coworker/getting-started-status → starter_credit_amount, starter_card_required, chat_platform_connect_bonus_credits GET /api/coworker/subscription → план (null = free) Печатает таблицу + пишет credits_report.json рядом с пулом. """ import json, os, sys, time, urllib.request, urllib.error API = "https://api.viktor.com" HERE = os.path.dirname(os.path.abspath(__file__)) POOL = sys.argv[1] if len(sys.argv) > 1 else os.path.join(HERE, "accounts.jsonl") REPORT = os.path.join(os.path.dirname(POOL), "credits_report.json") def get(path, jwt): req = urllib.request.Request(API + path, headers={ "User-Agent": "Mozilla/5.0", "Authorization": "Bearer " + jwt, "Origin": "https://app.viktor.com", "Referer": "https://app.viktor.com/"}) try: r = urllib.request.urlopen(req, timeout=30) return r.status, json.loads(r.read() or b"null") except urllib.error.HTTPError as e: return e.code, e.read()[:120].decode(errors="replace") except Exception as e: return -1, str(e)[:120] def main(): rows = [] with open(POOL, encoding="utf-8") as f: accs = [json.loads(l) for l in f if l.strip()] for a in accs: jwt = a.get("jwt") or "" if not jwt: continue email = a.get("email", "?") s1, gs = get("/api/coworker/getting-started-status", jwt) s2, sub = get("/api/coworker/subscription", jwt) row = {"email": email, "gs_http": s1, "sub_http": s2, "subscription": sub if s2 == 200 else None} if s1 == 200 and isinstance(gs, dict): row.update({ "starter_credit_amount": gs.get("starter_credit_amount"), "starter_card_required": gs.get("starter_card_required"), "connect_bonus": gs.get("chat_platform_connect_bonus_credits"), "has_sent_first_task": gs.get("has_sent_first_task"), }) rows.append(row) print(json.dumps(row, ensure_ascii=False)) time.sleep(1.0) # не злить rate-limit with open(REPORT, "w", encoding="utf-8") as f: json.dump(rows, f, ensure_ascii=False, indent=1) n_unlockable = sum(1 for r in rows if r.get("starter_credit_amount")) print(f"\ntotal={len(rows)} starter_credit_available={n_unlockable} report={REPORT}") if __name__ == "__main__": main()