douyinWEB/scripts/_fix_anchors_douyin_only.py
eric d409e416da Ship physical dual-edge stack, Studio CDP live metrics, and ops tooling.
Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-04 22:42:40 -05:00

66 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
"""Deploy Douyin-only anchors filter (exclude shorts:/yt: leakage)."""
from __future__ import annotations
import sys
from pathlib import Path
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
ROOT = Path(__file__).resolve().parents[1]
HOST = "108.174.50.68"
PASS = "Xiao4669805"
REPO = "/opt/douyinWEB"
FILES = [
"backend/app/db.py",
"frontend/src/components/DouyinLiveBadge.tsx",
"frontend/src/app/anchors/page.tsx",
]
def main() -> None:
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(HOST, 22, "root", PASS, timeout=60, allow_agent=False, look_for_keys=False)
sftp = c.open_sftp()
for rel in FILES:
sftp.put(str(ROOT / rel), f"{REPO}/{rel}")
print("uploaded", rel)
sftp.close()
cmd = r"""
set -e
systemctl restart douyinweb-api
cd /opt/douyinWEB/frontend && npm run build
systemctl restart douyinweb-web
sleep 3
cd /opt/douyinWEB/backend && .venv/bin/python - <<'PY'
from app import db
rows = db.list_anchors(limit=80)
leak = [r for r in rows if str(r.get("room_id") or "").startswith(("shorts:", "yt:"))]
print("anchors", len(rows), "leaks", len(leak))
for r in leak[:5]:
print("LEAK", r)
up = db.list_upcoming_opens(limit=20)
leak_up = [r for r in up if str(r.get("room_id") or "").startswith(("shorts:", "yt:"))]
print("upcoming", len(up), "leaks", len(leak_up))
assert not leak, leak
assert not leak_up, leak_up
print("ok")
PY
systemctl is-active douyinweb-api
systemctl is-active douyinweb-web
"""
_i, o, e = c.exec_command(cmd, timeout=700)
print(o.read().decode("utf-8", "replace"))
err = e.read().decode("utf-8", "replace")
if err.strip():
print("STDERR", err[-2000:])
c.close()
if __name__ == "__main__":
main()