douyinWEB/scripts/_deploy_yt_long_seo.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

56 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
REPO = "/opt/douyinWEB"
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)
def run(cmd, timeout=600):
_, o, e = c.exec_command(cmd, timeout=timeout)
out = (o.read() + e.read()).decode("utf-8", "replace").strip()
print(out[-4000:] if len(out) > 4000 else out, flush=True)
return out
seed_py = r'''
from app import db
from app import caption_pool
from app.yt_long_seo import pick_yt_long_seo, YT_LONG_TITLES, YT_LONG_DESCS
db.init_db()
with db._lock:
conn = db._connect()
try:
counts = caption_pool.seed_caption_pool(conn, force=False)
conn.commit()
print("seed", counts)
finally:
conn.close()
print("titles", len(YT_LONG_TITLES), "descs", len(YT_LONG_DESCS))
for _ in range(3):
p = pick_yt_long_seo()
print("---")
print("T:", p["title"])
print("D:", p["description"][:100].replace("\n", " | "))
'''
sftp = c.open_sftp()
with sftp.file("/tmp/yt_long_seed_seo.py", "w") as f:
f.write(seed_py)
sftp.close()
print("[pull]", run(f"cd {REPO} && git pull --ff-only origin test1 && git log --oneline -1"))
run("systemctl restart douyinweb-api")
for _ in range(30):
if run("systemctl is-active douyinweb-api", timeout=15) == "active":
break
time.sleep(2)
time.sleep(2)
print("[seed]", run("cd /opt/douyinWEB/backend && PYTHONPATH=. .venv/bin/python /tmp/yt_long_seed_seo.py"))
print("[build]", run(f"cd {REPO}/frontend && npm run build 2>&1 | tail -n 12", timeout=600))
run("systemctl restart douyinweb-web")
print("[svc]", run("systemctl is-active douyinweb-api douyinweb-web"))
c.close()
print("DONE")