# -*- coding: utf-8 -*- """Sync sh2 cookie + probe a few real rooms.""" from __future__ import annotations import asyncio import sys from pathlib import Path BACKEND = Path(r"C:\Users\admin\Desktop\douyinWEB\backend") sys.path.insert(0, str(BACKEND)) from app import cookie_loader, db # noqa: E402 from app.douyin import check_room # noqa: E402 async def main() -> None: db.init_db() sync = cookie_loader.force_sync_cookie_from_sh2() print("sync", {k: v for k, v in sync.items() if k != "cookie"}, flush=True) cfg = db.get_settings_map() cookie = str(cfg.get("dy_cookie") or "") print("has_cookie", bool(cookie), "len", len(cookie), flush=True) rooms = (db.list_rooms(limit=2000).get("rooms") or [])[:5] if not rooms: print("no rooms", flush=True) return for r in rooms: url = r["url"] note = r.get("note") or "" try: result = await check_room(url, cookie=cookie) print( "probe", r.get("room_id"), note[:20], "ok=", result.get("ok"), "status=", result.get("status"), "live=", result.get("is_live"), "anchor=", (result.get("anchor_name") or "")[:20], "err=", result.get("error") or "", flush=True, ) except Exception as exc: print("probe_fail", r.get("room_id"), type(exc).__name__, exc, flush=True) await asyncio.sleep(2.5) # clear risk pause after successful path validation db.update_settings_map({"monitor_enabled": True}) print("done rooms=", db.counts(), flush=True) if __name__ == "__main__": asyncio.run(main())