# -*- coding: utf-8 -*- import sys, time, paramiko from pathlib import Path sys.stdout.reconfigure(encoding="utf-8", errors="replace") ROOT = Path(__file__).resolve().parents[1] REMOTE = r""" cd /opt/douyinWEB/backend && .venv/bin/python3 <<'PY' import time from app import yt_assign_db from app.yt_assign_db import _connect, ensure_yt_assign_tables EVAN = "6c42de20-1577-40c4-bd7b-c2cf0005dd77" NOMAD = "1cc3e3f0-02cf-4216-9780-d5015f338a6e" now = time.time() conn = _connect() ensure_yt_assign_tables(conn) conn.execute( "UPDATE yt_assign_groups SET name=?, note=?, updated_at=? WHERE id=?", ("Evan HomeLab", "@evan_homelab · Neko #6", now, EVAN), ) conn.execute( "UPDATE yt_assign_groups SET enabled=1, name=?, note=?, updated_at=? WHERE id=?", ("nomadvps", "@nomadvps · Neko #7", now, NOMAD), ) conn.commit() conn.close() sched = yt_assign_db.build_rotation_schedule(include_urls=False, keyed_only=True) print('channel_count', sched.get('channel_count'), 'slot_hours', sched.get('slot_hours')) for c in sched.get('channels') or []: print(c.get('start_label'), c.get('end_label'), c.get('name'), 'active', c.get('active')) PY systemctl restart douyinweb-api """ c=paramiko.SSHClient(); c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect('108.174.50.68',22,'root','Xiao4669805',timeout=60,allow_agent=False,look_for_keys=False) sftp=c.open_sftp() sftp.put(str(ROOT/'backend/app/yt_assign_db.py'), '/opt/douyinWEB/backend/app/yt_assign_db.py') sftp.close() chan=c.get_transport().open_session() chan.settimeout(120) chan.exec_command(REMOTE) out=b'' while True: if chan.recv_ready(): out+=chan.recv(8192) elif chan.exit_status_ready(): while chan.recv_ready(): out+=chan.recv(8192) break if not chan.recv_ready() and not chan.exit_status_ready(): import time; time.sleep(0.3) continue print(out.decode('utf-8','replace')) print('exit', chan.recv_exit_status() if chan.exit_status_ready() else '?') c.close()