#!/usr/bin/env python3 """ TokenHarbor batch runner: runs multiple batches of th_tonline_claim.py until we have enough keys. """ # __portable_paths__ (auto-injected: portable, env-overridable paths) import os as _pos, sys as _psys from pathlib import Path as _PPath _ROOT = _PPath(__file__).resolve().parent _REPO = _ROOT for _ in range(4): if (_REPO / ".git").exists() or (_REPO / "README.md").exists(): break if _REPO.parent == _REPO: break _REPO = _REPO.parent _DATA = _PPath(_pos.environ.get("TOOLKIT_DATA", str(_REPO / "data"))) _WORK = _PPath(_pos.environ.get("TOOLKIT_WORK", str(_REPO / "_work"))) try: _DATA.mkdir(parents=True, exist_ok=True) _WORK.mkdir(parents=True, exist_ok=True) except Exception: pass _PY = _pos.environ.get("PYTHON_BIN") or _psys.executable _USERPROFILE = _pos.environ.get("USERPROFILE") or str(_PPath.home()) def _d(name, env=None): """Data-file path under ./data (or $TOOLKIT_DATA); optional per-file env override.""" if env and _pos.environ.get(env): return _PPath(_pos.environ[env]) return _DATA / name def _w(name=""): """Work-dir path under ./_work (or $TOOLKIT_WORK).""" return (_WORK / name) if name else _WORK # --- end portable prelude --- import subprocess, json, time, sys from pathlib import Path STATE_FILE = Path(__file__).parent / "th_tonline_state.json" TARGET = 200 # Total target accounts BATCH_SIZE = 100 def restart_chrome(): """Kill and restart Chrome with CDP""" subprocess.run("taskkill /F /IM chrome.exe 2>nul", shell=True) time.sleep(2) chrome_temp = str(_w("AppData/Local/Temp/chrome_cdp")) subprocess.Popen([ r"C:\Program Files\Google\Chrome\Application\chrome.exe", "--remote-debugging-port=9222", "--remote-allow-origins=*", f"--user-data-dir={chrome_temp}", "--no-first-run", "--no-default-browser-check", "about:blank" ]) time.sleep(5) while True: state = json.load(open(STATE_FILE)) if STATE_FILE.exists() else {"done": [], "fail": []} done = len(state["done"]) if done >= TARGET: print(f"\nTARGET REACHED: {done} done, stopping") break remaining = TARGET - done batch = min(BATCH_SIZE, remaining) print(f"\nRunning batch: {batch} accounts (have {done}, need {TARGET})") # Check if Chrome is running import urllib.request try: urllib.request.urlopen("http://127.0.0.1:9222/json/version", timeout=5) except: print("Chrome not running, restarting...") restart_chrome() result = subprocess.run( ["python", "-u", "th_tonline_claim.py", str(batch)], cwd=Path(__file__).parent, capture_output=False, timeout=600 ) if result.returncode != 0: print(f"Batch failed with exit code {result.returncode}") # Check if Chrome died try: urllib.request.urlopen("http://127.0.0.1:9222/json/version", timeout=5) except: restart_chrome() continue # Update state state = json.load(open(STATE_FILE)) done = len(state["done"]) print(f"Progress: {done}/{TARGET}") print("Done!")