douyinWEB/scripts/_cmp_dylive_dy_neko_studio.py
2026-09-13 22:10:49 -05:00

102 lines
3.1 KiB
Python

#!/usr/bin/env python3
"""Compare dylive (good) vs dy (broken) for Studio scrape / neko — read only."""
from __future__ import annotations
import hashlib
import sys
import time
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
PASS = "Xiao4669805"
HOSTS = [("dylive", "107.173.30.245"), ("dy", "108.174.50.68")]
LOCAL = Path(r"c:\Users\admin\Desktop\douyinWEB\backend\app\youtube_neko.py")
CMD = r"""
echo HOST=$(hostname)
echo api=$(systemctl is-active douyinweb-api)
sha256sum /opt/douyinWEB/backend/app/youtube_neko.py | awk '{print "neko_py",$1}'
# markers
grep -c 'relay may leave Chrome' /opt/douyinWEB/backend/app/youtube_neko.py || echo marker0
grep -c 'Evidence-first' /opt/douyinWEB/backend/app/youtube_neko.py || true
cd /opt/douyinWEB/backend
./.venv/bin/python - <<'PY'
import json
from app import youtube_neko, yt_assign_db
def st(nid):
try:
return bool(youtube_neko._container_state(nid, check_http=False).get('running'))
except Exception:
return False
print('cdp_poll_ids', youtube_neko._neko_ids_for_cdp_poll())
rows=[]
for g in yt_assign_db.list_groups(include_urls=False):
nid=int(g.get('neko_instance_id') or 0)
if nid<1: continue
run=st(nid)
en=bool(g.get('neko_enabled'))
if not (en or run):
continue
snap=youtube_neko.studio_snapshot_for_group(g, max_age_sec=180)
rows.append({
'name': g.get('name'),
'nid': nid,
'neko_enabled': en,
'running': run,
'prefer': g.get('neko_open_prefer'),
'ops_slot': int(g.get('ops_neko_slot') or 0),
'page': snap.get('live_page_open'),
'air': snap.get('on_air'),
'viewers': snap.get('viewer_count'),
'src': snap.get('detect_source') or '',
'ui': snap.get('ui_source') or '',
'url': (snap.get('url') or '')[:70],
})
print('active_groups', len(rows))
for r in rows:
print(json.dumps(r, ensure_ascii=False))
# docker
import subprocess
out=subprocess.check_output(['docker','ps','--filter','name=douyinweb-neko','--format','{{.Names}} {{.Status}}'], text=True)
print('DOCKER')
print(out.strip() or '(none)')
PY
"""
def connect(host):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(6):
try:
c.connect(host, 22, "root", PASS, timeout=30, allow_agent=False, look_for_keys=False)
return c
except Exception as e:
print(host, e, flush=True)
time.sleep(1 + i)
raise SystemExit(f"fail {host}")
def main():
print("local_neko_py", hashlib.sha256(LOCAL.read_bytes()).hexdigest()[:12], flush=True)
for name, host in HOSTS:
print(f"\n########## {name} {host} ##########", flush=True)
c = connect(host)
_i, o, e = c.exec_command(CMD, timeout=90)
print(o.read().decode("utf-8", "replace"), flush=True)
err = e.read().decode("utf-8", "replace")
if err.strip():
print("[stderr]", err[:800], flush=True)
c.close()
print("CMP_DONE", flush=True)
if __name__ == "__main__":
main()