52 lines
2.4 KiB
Python
52 lines
2.4 KiB
Python
|
|
import os, paramiko, json
|
||
|
|
PW = os.environ["REMOTE_PASS"]
|
||
|
|
c = paramiko.SSHClient()
|
||
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
||
|
|
c.connect("207.57.129.228", port=19717, username="root", password=PW, timeout=15, allow_agent=False, look_for_keys=False)
|
||
|
|
def run(cmd, t=20):
|
||
|
|
si, so, se = c.exec_command(cmd, timeout=t)
|
||
|
|
out = so.read().decode("utf-8", "replace")
|
||
|
|
err = se.read().decode("utf-8", "replace")
|
||
|
|
rc = so.channel.recv_exit_status()
|
||
|
|
if out: print(out, end="")
|
||
|
|
if err: print("[err]", err, end="", file=__import__("sys").stderr)
|
||
|
|
return out
|
||
|
|
|
||
|
|
# 拿一条已翻译的(随便挑)
|
||
|
|
print("--- 拉 3 篇文章看译文 ---")
|
||
|
|
out = run("docker exec news-aggregator-postgres-1 psql -U news -d news -c \"SELECT id, source_id, title, title_zh, translation_engine, translation_chars, lang_src FROM articles WHERE translation_status = 'ok' ORDER BY translation_chars DESC LIMIT 3;\"")
|
||
|
|
print(out)
|
||
|
|
|
||
|
|
# 拿一条详情,看完整翻译
|
||
|
|
print("\n--- 登录 + 拉详情 ---")
|
||
|
|
body = json.dumps({"username": "owner", "password": "Owner2026!"})
|
||
|
|
out = run(f"curl -s -X POST http://localhost/api/v1/auth/login -H 'Content-Type: application/json' -d '{body}'")
|
||
|
|
token = json.loads(out)["access_token"]
|
||
|
|
|
||
|
|
# 找一篇 BBC 的(大概率有图)
|
||
|
|
out = run(f"curl -s -H 'Authorization: Bearer {token}' 'http://localhost/api/v1/articles?source=bbc-world&limit=1'")
|
||
|
|
ad = json.loads(out)
|
||
|
|
if ad.get("items"):
|
||
|
|
aid = ad["items"][0]["id"]
|
||
|
|
out = run(f"curl -s -H 'Authorization: Bearer {token}' 'http://localhost/api/v1/articles/{aid}'")
|
||
|
|
det = json.loads(out)
|
||
|
|
print(f"\n=== {det['source']['name']} - {det['title'][:60]} ===")
|
||
|
|
print(f"\n原文标题: {det['title'][:120]}")
|
||
|
|
print(f"中文标题: {(det.get('title_zh') or '—')[:120]}")
|
||
|
|
print(f"\n原文(前 300): {det['body_text'][:300]}")
|
||
|
|
print(f"\n译文(前 400): {(det.get('body_zh_text') or '—')[:400]}")
|
||
|
|
print(f"\nstatus: {det['translation_status']}")
|
||
|
|
print(f"engine: {det.get('translation_engine')}")
|
||
|
|
print(f"chars: {det.get('translation_chars', '?')}")
|
||
|
|
print(f"img: {det.get('image_url', '—')[:80]}")
|
||
|
|
|
||
|
|
# 用量
|
||
|
|
print("\n--- /me/usage ---")
|
||
|
|
u = json.loads(run(f"curl -s -H 'Authorization: Bearer {token}' 'http://localhost/api/v1/me/usage'"))
|
||
|
|
print(f" {u}")
|
||
|
|
|
||
|
|
# 容器状态
|
||
|
|
print("\n--- docker ps ---")
|
||
|
|
run("docker ps --format 'table {{.Names}}\\t{{.Status}}\\t{{.Ports}}' 2>&1 | tail -10")
|
||
|
|
c.close()
|