# -*- coding: utf-8 -*- from __future__ import annotations import json import urllib.request import paramiko HOST, USER, PASS = "82.157.112.245", "ubuntu", "Xiao4669805" def main() -> None: 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) _, o, e = c.exec_command( "sudo systemctl restart nomadmini-api.service && sleep 2 && " "systemctl is-active nomadmini-api.service && " "curl -s http://127.0.0.1:8010/health", timeout=60, ) print(o.read().decode()) err = e.read().decode() if err: print("STDERR", err[-1000:]) c.close() req = urllib.request.Request( "https://api.nomadro.cn/api/admin/login", data=json.dumps({"username": "admin", "password": "Xiao4669805"}).encode(), headers={"Content-Type": "application/json"}, method="POST", ) tok = json.loads(urllib.request.urlopen(req, timeout=20).read()).get("token", "") req2 = urllib.request.Request( "https://api.nomadro.cn/api/admin/product-offers", headers={"Authorization": "Bearer " + tok}, ) items = json.loads(urllib.request.urlopen(req2, timeout=20).read()).get("items") or [] for o in items: print(o.get("key"), o.get("product_id"), o.get("name"), o.get("price_yuan"), o.get("remark")) if __name__ == "__main__": main()