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

94 lines
2.9 KiB
Python

# -*- coding: utf-8 -*-
"""Check/seed caption_pool on physical via FRP (upload script + sudo)."""
from __future__ import annotations
import sys
import time
import paramiko
if hasattr(sys.stdout, "reconfigure"):
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
REMOTE_PY = r'''
import sqlite3, json, os, sys
sys.path.insert(0, "/opt/douyinWEB/backend")
os.chdir("/opt/douyinWEB/backend")
p = "/opt/douyinWEB/backend/data/monitor.db"
con = sqlite3.connect(p)
con.row_factory = sqlite3.Row
tabs = {r[0] for r in con.execute("SELECT name FROM sqlite_master WHERE type='table'")}
print("has_caption_pool", "caption_pool" in tabs)
if "caption_pool" in tabs:
for r in con.execute(
"SELECT platform, COUNT(*) n, SUM(CASE WHEN enabled=1 THEN 1 ELSE 0 END) en FROM caption_pool GROUP BY platform"
):
print("pool", dict(r))
else:
print("NO_TABLE caption_pool")
cols = [r[1] for r in con.execute("PRAGMA table_info(shorts_jobs)")]
want = [c for c in ("id","status","error","title","upload_title","anchor_name","channel_handle","room_id","created_at") if c in cols]
print("want", want)
if want:
for row in con.execute("SELECT %s FROM shorts_jobs ORDER BY rowid DESC LIMIT 8" % ",".join(want)):
d = dict(row)
d["error"] = str(d.get("error") or "")[:200]
print("job", d)
for t in sorted(tabs):
ccols = [r[1] for r in con.execute(f"PRAGMA table_info({t})")]
if "title_template" in ccols:
sel = [c for c in ccols if c in ("id","label","name","handle","channel_handle","title_template","note","enabled")]
print("table", t)
for r in con.execute(f"SELECT {','.join(sel)} FROM {t} LIMIT 12"):
print(" ch", dict(r))
con.close()
from app import caption_pool, db
with db._lock:
conn = db._connect()
try:
caption_pool.ensure_caption_pool_table(conn)
counts = caption_pool.seed_caption_pool(conn, force=False)
conn.commit()
print("seed_counts", counts)
for r in conn.execute("SELECT platform, COUNT(*) n FROM caption_pool GROUP BY platform"):
print("after", dict(r))
finally:
conn.close()
picked = caption_pool.pick_caption(
"shorts", custom="{anchor} #Shorts", anchor="阿珍", url="https://live.douyin.com/x", room="x"
)
print("pick", picked)
'''
def main():
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(
"107.173.30.245",
4014,
"eric",
"4669805",
timeout=45,
allow_agent=False,
look_for_keys=False,
)
sftp = c.open_sftp()
with sftp.file("/tmp/_cap_pool_check.py", "w") as f:
f.write(REMOTE_PY)
sftp.close()
_, o, e = c.exec_command(
"echo '4669805' | sudo -S -p '' /opt/douyinWEB/backend/.venv/bin/python /tmp/_cap_pool_check.py",
timeout=120,
)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()
if __name__ == "__main__":
main()