# -*- coding: utf-8 -*- """Deploy YouTube ntfy backend changes.""" import time import paramiko HOST = "107.173.30.245" REPO = "/opt/douyinWEB" LOCAL = r"C:/Users/admin/Desktop/douyinWEB" FILES = [ "backend/app/notify.py", "backend/app/youtube_monitor.py", "backend/app/db.py", ] c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(HOST, 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False) def run(cmd: str, timeout: int = 120) -> str: _, o, e = c.exec_command(cmd, timeout=timeout) out = o.read().decode("utf-8", "replace").strip() err = e.read().decode("utf-8", "replace").strip() return (out + ("\n" + err if err else "")).strip() ts = int(time.time()) print("[backup]", run(f"cp -a {REPO}/backend/data/monitor.db /tmp/monitor.db.bak_yt_ntfy_{ts} && ls -lh /tmp/monitor.db.bak_yt_ntfy_{ts}")) sftp = c.open_sftp() for rel in FILES: remote = f"{REPO}/{rel.replace(chr(92), '/')}" local = f"{LOCAL}/{rel.replace(chr(92), '/')}" print("[upload]", rel) sftp.put(local, remote) sftp.close() print("[verify]", run(f"grep -n send_ntfy_youtube {REPO}/backend/app/notify.py | head -2")) print("[api restart]", run("systemctl restart douyinweb-api; sleep 5; systemctl is-active douyinweb-api")) print("[ntfy cfg]", run("test -f /etc/nomadro/ntfy.env && echo OK || echo MISSING")) c.close() print("DONE")