import os, time, json, urllib.request PORTS = [16970, 16971, 16972, 16973, 16974, 16975, 16976, 16977] SHM_P = "/dev/shm/jc_desktop_ani_pool.json" no_px = urllib.request.build_opener(urllib.request.ProxyHandler({})) while True: ready = [] for p in PORTS: try: with no_px.open(f"http://127.0.0.1:{p}/?backend=macos", timeout=1.5) as r: j = json.loads(r.read().decode("utf-8", "ignore")) if j.get("X-Apple-I-MD") and j.get("X-Apple-I-MD-M"): j["_ts"] = time.time() j["_local"] = True j["_port"] = p ready.append(j) except Exception: pass if ready: try: tp = f"{SHM_P}.d.tmp" with open(tp, "w") as f: json.dump({"ts": time.time(), "tokens": ready, "cooldowns": {}}, f) os.replace(tp, SHM_P) except Exception: pass time.sleep(8)