# -*- coding: utf-8 -*- """Push social live API router + smoke join via api.nomadro.cn.""" from __future__ import annotations import time from pathlib import Path import paramiko REPO = Path(__file__).resolve().parents[3] HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805" def main() -> int: c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect( HOST, username=USER, password=PASS, timeout=60, allow_agent=False, look_for_keys=False, ) sftp = c.open_sftp() local = REPO / "apps/api/services/social_svc/routers/api.py" with sftp.file("/tmp/social_routers_api.py", "wb") as rf: rf.write(local.read_bytes()) sftp.close() cmd = r""" set -e sudo cp /tmp/social_routers_api.py /var/www/nomadro.cn/apps/api/services/social_svc/routers/api.py sudo systemctl restart nomadro-social sleep 2 systemctl is-active nomadro-social curl -sk --max-time 8 -X POST 'https://api.nomadro.cn/api/social/v1/live/rooms/office/join?guest=weapp_real_2' \ -H 'Content-Type: application/json' \ --data-binary '{"nick":"真机"}' | head -c 420; echo curl -sk --max-time 5 'https://api.nomadro.cn/api/social/v1/health'; echo """ _, stdout, _ = c.exec_command(cmd, timeout=60, get_pty=True) while not stdout.channel.exit_status_ready(): if stdout.channel.recv_ready(): print(stdout.channel.recv(65536).decode("utf-8", "replace"), end="", flush=True) time.sleep(0.05) while stdout.channel.recv_ready(): print(stdout.channel.recv(65536).decode("utf-8", "replace"), end="", flush=True) code = stdout.channel.recv_exit_status() print(f"[exit {code}]", flush=True) c.close() return code if __name__ == "__main__": raise SystemExit(main())