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

70 lines
2.1 KiB
Python

#!/usr/bin/env python3
"""Add pool urls into slots for newly synced time_slot groups on dylive."""
from __future__ import annotations
import sys
import time
import paramiko
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
def ssh(host: str):
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
for i in range(6):
try:
c.connect(
host,
22,
"root",
"Xiao4669805",
timeout=50,
allow_agent=False,
look_for_keys=False,
banner_timeout=180,
)
return c
except Exception as e:
print("retry", i, e)
time.sleep(2)
raise SystemExit("fail")
c = ssh("107.173.30.245")
_i, o, e = c.exec_command(
r"""
cd /opt/douyinWEB/backend
./.venv/bin/python - <<'PY'
from app import yt_assign_db
for name in ('china street food', 'nice street food'):
g = next((x for x in yt_assign_db.list_groups(include_urls=True, include_secret=False) if x.get('name')==name), None)
if not g:
print('missing', name); continue
gid = g['id']
slots = g.get('slots') or []
pool = g.get('pool') or []
print(name, 'slots_before', len(slots), 'pool', len(pool))
if slots:
print(' already has slots'); continue
ids = [p['id'] for p in pool if p.get('id')]
if not ids:
print(' no pool ids'); continue
print(' add_slot', yt_assign_db.add_slot(gid, ids))
g2 = yt_assign_db.get_group(gid, include_secret=False)
print(' slots_after', len(g2.get('slots') or []), 'cat', g2.get('category'))
gs = yt_assign_db.list_groups(include_urls=False, include_secret=True)
print('assign', len(gs), 'full', sum(1 for g in gs if len(str(g.get('stream_key')or''))>=12))
from app import yt_stream_key_db
print('registry', yt_stream_key_db.list_entries()['total'])
PY
docker ps --filter name=douyinweb-neko-12 --format '{{.Names}} {{.Status}}'
docker exec douyinweb-neko-12 supervisorctl status google-chrome | head -1
""",
timeout=120,
)
print((o.read() + e.read()).decode("utf-8", "replace"))
c.close()