sh2/d2ypp2/tools/query_host03_opt_live.py
eric 278b48497e Add YouTube relay log tooling and optional hub service controls.
This captures the current live stack updates across the API, Linux service scripts, tests, diagnostics, and exported console assets so the Ubuntu deployment can pull a consistent test3 build.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-30 05:10:09 -05:00

63 lines
2.8 KiB
Python

#!/usr/bin/env python3
"""Query /opt/live/d2ypp on 10.88.0.3 for lane1 douyin source and history."""
from __future__ import annotations
import json
import paramiko
HOST, USER, PASS = "10.88.0.3", "eric", "Xiao4669805"
BASE = "/opt/live/d2ypp"
SRC = "/home/eric/d2ypp2-src"
def q(cmd: str, timeout: int = 120) -> str:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, username=USER, password=PASS, timeout=15)
_, o, e = c.exec_command(cmd, timeout=timeout, get_pty=True)
out = (o.read() + e.read()).decode("utf-8", "replace")
c.close()
return out
CMDS = [
("date", "date; uptime"),
("url_config_youtube", f"cat {BASE}/config/URL_config.youtube.ini 2>/dev/null; echo '---SRC---'; cat {SRC}/config/URL_config.youtube.ini 2>/dev/null"),
("url_config_lane2", f"cat {BASE}/config/URL_config.youtube2__ch_mpykhmnj_lsrv7.ini 2>/dev/null"),
(
"hub_sqlite",
f"sqlite3 {SRC}/config/hub_state.sqlite '.tables' 2>/dev/null; "
f"sqlite3 {SRC}/config/hub_state.sqlite \"SELECT key, substr(value,1,8000) FROM kv\" 2>/dev/null; "
f"sqlite3 {BASE}/config/hub_state.sqlite '.tables' 2>/dev/null; "
f"sqlite3 {BASE}/config/hub_state.sqlite \"SELECT key, substr(value,1,8000) FROM kv\" 2>/dev/null",
),
("pm2_opt", f"PM2_HOME={BASE}/.pm2 pm2 list 2>/dev/null; PM2_HOME={BASE}/.pm2 pm2 jlist 2>/dev/null | head -c 8000"),
("logs_opt", f"find {BASE}/.pm2/logs -type f -printf '%T@ %TY-%Tm-%Td %TH:%TM %p %s\\n' 2>/dev/null | sort -nr | head -20"),
("grep_douyin_opt", f"grep -hE 'live.douyin.com|source|room|title|start|stop' {BASE}/.pm2/logs/*.log 2>/dev/null | tail -100"),
("youtube_live_store", f"find {BASE} {SRC} -name '*live*store*' -o -name '*youtube*event*' -o -name '*session*' 2>/dev/null | head -20"),
("api_hub", "curl -sS -m 20 'http://127.0.0.1:8001/hub/dashboard' 2>/dev/null | head -c 12000"),
("api_process", "curl -sS -m 20 'http://127.0.0.1:8001/process_monitor?family=youtube' 2>/dev/null"),
("backup_urls", f"ls -lt {SRC}/backup_config/URL_config.youtube.ini_* 2>/dev/null | head -10; echo '---'; for f in $(ls -t {SRC}/backup_config/URL_config.youtube.ini_* 2>/dev/null | head -5); do echo \"=== $f ===\"; cat \"$f\"; done"),
]
def main() -> int:
for label, cmd in CMDS:
print(f"\n{'='*60}\n=== {label} ===\n{'='*60}")
try:
out = q(cmd)
if out.strip().startswith(("{", "[")):
try:
print(json.dumps(json.loads(out), ensure_ascii=False, indent=2)[:15000])
continue
except Exception:
pass
print(out[:20000].encode("ascii", "backslashreplace").decode())
except Exception as exc:
print(f"ERR: {exc}")
return 0
if __name__ == "__main__":
raise SystemExit(main())