#!/usr/bin/env python3 """Deploy books_live.py with vip library free sync to api.nomadro.cn.""" from __future__ import annotations import io import time from pathlib import Path import paramiko HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805" SRC = ( Path(__file__).resolve().parents[3] / "apps" / "api" / "services" / "ebook_svc" / "services" / "books_live.py" ) def main() -> int: text = SRC.read_text(encoding="utf-8").replace("ebook_svc.", "app.").encode("utf-8") c = paramiko.SSHClient() c.set_missing_host_key_policy(paramiko.AutoAddPolicy()) c.connect(HOST, username=USER, password=PASS, timeout=40, allow_agent=False, look_for_keys=False) sftp = c.open_sftp() sftp.putfo(io.BytesIO(text), "/tmp/books_live.py") sftp.close() remote = r""" set -euo pipefail sudo cp /tmp/books_live.py /opt/nomadmini/backend/app/services/books_live.py # wire free= into admin offer bump if missing python3 - <<'PY' from pathlib import Path p=Path('/opt/nomadmini/backend/app/routers/admin.py') t=p.read_text(encoding='utf-8') old="bump_books_offer_live(book_id)" new="bump_books_offer_live(book_id, free=is_book_free(updated if 'updated' in dir() else book))" # safer: leave calls as-is; books_live free=None still bumps rev print('admin bump calls', t.count('bump_books_offer_live')) PY sudo systemctl restart nomadmini-api sleep 3 systemctl is-active nomadmini-api cd /opt/nomadmini/backend && .venv/bin/python -c "from app.services.books_live import bump_books_offer_live, sync_vip_library_free; print('ok', callable(sync_vip_library_free))" curl -sk -o /dev/null -w 'health %{http_code}\n' https://api.nomadro.cn/health || true """ _, stdout, _ = c.exec_command(remote, timeout=90, 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() c.close() return code if __name__ == "__main__": raise SystemExit(main())