douyinWEB/scripts/probe_offline_cover.py
eric a360eec2ba Document slots/covers/PB ops UX and sync feature pass to main.
Ship zombie reconcile, S3 covers, session end/drill-down, rooms ops, and refresh README for production.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-08 20:07:15 -05:00

73 lines
2.8 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# -*- coding: utf-8 -*-
import json
import paramiko
SCRIPT = r'''
import sys, asyncio, json, sqlite3
sys.path.insert(0, "/opt/douyinWEB/backend")
from app.douyin import _fetch_web_enter, check_room, _normalize_result
from app import db
import httpx
cfg = db.get_settings_map()
cookie = str(cfg.get("dy_cookie") or "")
conn = sqlite3.connect("/opt/douyinWEB/backend/data/monitor.db")
conn.row_factory = sqlite3.Row
# sessions missing cover with room
rows = conn.execute("""
SELECT s.anchor_name, s.room_id, r.url, r.last_status
FROM sessions s
LEFT JOIN rooms r ON r.id = s.room_pk
WHERE (s.cover_path IS NULL OR trim(s.cover_path)='')
AND s.anchor_name IN ('雨汐在农村','大墨鱼(硕士裸辞摆摊ing)','小媛发面鸡蛋饼')
""").fetchall()
print("targets", [dict(x) for x in rows])
async def inspect(url, rid, name):
print("====", name, rid)
async with httpx.AsyncClient(timeout=20, verify=False, trust_env=False) as client:
room = await _fetch_web_enter(client, rid, cookie=cookie)
print("keys", sorted(room.keys())[:40])
print("status", room.get("status"), "has_cover", "cover" in room, "has_owner", "owner" in room)
if room.get("cover"):
print("cover", json.dumps(room.get("cover"), ensure_ascii=False)[:220])
owner = room.get("owner") or {}
if isinstance(owner, dict) and owner.get("avatar_thumb"):
print("avatar", json.dumps(owner.get("avatar_thumb"), ensure_ascii=False)[:220])
# also dump user-level if present? enter wrapper
norm = _normalize_result(room, url)
print("norm cover_image", (norm.get("cover_image") or "")[:120], "stream", bool(norm.get("stream_url")), "live", norm.get("is_live"))
probed = await check_room(url, cookie=cookie)
print("check_room cover", (probed.get("cover_image") or "")[:120], "err", probed.get("error"))
async def main():
for r in rows:
if not r["url"]:
print("no url", r["anchor_name"]); continue
await inspect(r["url"], r["room_id"], r["anchor_name"])
await asyncio.sleep(1.2)
asyncio.run(main())
'''
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
# upload fixed files that may not have been latest for cover.py force
sftp = c.open_sftp()
from pathlib import Path
LOCAL = Path(r"C:\Users\admin\Desktop\douyinWEB")
for rel in ["backend/app/cover.py", "backend/app/main.py"]:
sftp.put(str(LOCAL / rel), f"/opt/douyinWEB/{rel}")
sftp.close()
_, o, e = c.exec_command(
"systemctl restart douyinweb-api --no-block; sleep 3; "
"/opt/douyinWEB/backend/.venv/bin/python - <<'PY'\n" + SCRIPT + "\nPY",
timeout=120,
)
print(o.read().decode("utf-8", "replace"))
err = e.read().decode("utf-8", "replace")
if err.strip():
print("ERR", err[-2000:])
c.close()