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>
118 lines
3.9 KiB
Python
118 lines
3.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Deploy total_views + live_duration scrape/UI. API restart only; no Chrome touch."""
|
|
from __future__ import annotations
|
|
|
|
import sys
|
|
import time
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
PASS = "4669805"
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
|
|
FILES = [
|
|
("backend/app/youtube_neko.py", "/tmp/_tv_neko.py"),
|
|
("backend/app/youtube_relay_pipeline.py", "/tmp/_tv_relay.py"),
|
|
("backend/neko/cdp_studio_scrape.py", "/tmp/_tv_scrape.py"),
|
|
("backend/neko/live-ops-extension/content.js", "/tmp/_tv_content.js"),
|
|
("frontend/src/components/StudioViewerChart.tsx", "/tmp/_tv_chart.tsx"),
|
|
("frontend/src/components/YtRelayProStatusPanel.tsx", "/tmp/_tv_panel.tsx"),
|
|
("frontend/src/lib/ytRelayStatus.ts", "/tmp/_tv_status.ts"),
|
|
]
|
|
|
|
SH = r"""#!/bin/bash
|
|
set -euo pipefail
|
|
install -m 644 /tmp/_tv_neko.py /opt/douyinWEB/backend/app/youtube_neko.py
|
|
install -m 644 /tmp/_tv_relay.py /opt/douyinWEB/backend/app/youtube_relay_pipeline.py
|
|
install -m 644 /tmp/_tv_scrape.py /opt/douyinWEB/backend/neko/cdp_studio_scrape.py
|
|
install -m 644 /tmp/_tv_content.js /opt/douyinWEB/backend/neko/live-ops-extension/content.js
|
|
install -m 644 /tmp/_tv_chart.tsx /opt/douyinWEB/frontend/src/components/StudioViewerChart.tsx
|
|
install -m 644 /tmp/_tv_panel.tsx /opt/douyinWEB/frontend/src/components/YtRelayProStatusPanel.tsx
|
|
install -m 644 /tmp/_tv_status.ts /opt/douyinWEB/frontend/src/lib/ytRelayStatus.ts
|
|
|
|
BEFORE=$(docker ps -q --filter name=douyinweb-neko- | wc -l | tr -d ' ')
|
|
systemctl restart douyinweb-api
|
|
sleep 4
|
|
systemctl is-active douyinweb-api
|
|
AFTER=$(docker ps -q --filter name=douyinweb-neko- | wc -l | tr -d ' ')
|
|
echo "NEKO_BEFORE=$BEFORE NEKO_AFTER=$AFTER"
|
|
test "$BEFORE" = "$AFTER"
|
|
|
|
systemctl stop douyinweb-web || true
|
|
cd /opt/douyinWEB/frontend && npm run build
|
|
systemctl start douyinweb-web
|
|
sleep 2
|
|
systemctl is-active douyinweb-web
|
|
|
|
echo SMOKE_CDP
|
|
cd /opt/douyinWEB/backend
|
|
PYTHONPATH=/opt/douyinWEB/backend .venv/bin/python - <<'PY'
|
|
import json
|
|
from app import youtube_neko as yn
|
|
# Force one poll so new fields land in minute reports
|
|
out = yn.poll_studio_cdp_once()
|
|
print(json.dumps({"count": out.get("count")}, ensure_ascii=False))
|
|
for row in out.get("polled") or []:
|
|
nid = row.get("neko_instance_id")
|
|
if not row.get("ok"):
|
|
print("neko", nid, row.get("error"))
|
|
continue
|
|
# Re-read latest cache
|
|
sig = yn._cdp_signal_cache.get(int(nid), (0, {}))[1] # noqa: SLF001
|
|
print(
|
|
f"neko{nid}",
|
|
"on_air", sig.get("on_air"),
|
|
"conc", sig.get("viewer_count"),
|
|
"views", sig.get("total_views"),
|
|
"dur", sig.get("live_duration"),
|
|
"status", sig.get("live_status"),
|
|
)
|
|
PY
|
|
echo DEPLOY_OK
|
|
"""
|
|
|
|
|
|
def main() -> int:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
for i in range(12):
|
|
try:
|
|
c.connect(
|
|
"107.173.30.245",
|
|
4014,
|
|
"eric",
|
|
PASS,
|
|
timeout=60,
|
|
banner_timeout=120,
|
|
allow_agent=False,
|
|
look_for_keys=False,
|
|
)
|
|
break
|
|
except Exception as ex:
|
|
print("ssh", i, type(ex).__name__, flush=True)
|
|
time.sleep(2)
|
|
else:
|
|
return 1
|
|
sftp = c.open_sftp()
|
|
for rel, tmp in FILES:
|
|
with sftp.file(tmp, "wb") as f:
|
|
f.write((ROOT / rel).read_bytes())
|
|
print("up", rel, flush=True)
|
|
with sftp.file("/tmp/_tv_deploy.sh", "w") as f:
|
|
f.write(SH)
|
|
sftp.close()
|
|
_, o, e = c.exec_command(
|
|
f"echo '{PASS}' | sudo -S -p '' bash /tmp/_tv_deploy.sh",
|
|
timeout=900,
|
|
)
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
print(out[-12000:] if len(out) > 12000 else out)
|
|
c.close()
|
|
return 0 if "DEPLOY_OK" in out else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|