48 lines
1.7 KiB
Python
48 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
import sys
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
REMOTE = r'''#!/bin/bash
|
|
cd /opt/douyinWEB/backend
|
|
./.venv/bin/python - <<'PY'
|
|
from app import db
|
|
from app import yt_assign_db
|
|
groups = yt_assign_db.list_groups(include_urls=False)
|
|
print("=== shorts oauth for assign channel_pks ===")
|
|
for g in groups:
|
|
pk = str(g.get("channel_pk") or "")
|
|
name = g.get("name")
|
|
ch = db.get_shorts_channel(pk) if pk else None
|
|
if not ch:
|
|
print(f"MISSING_CH | {name} | pk={pk}")
|
|
continue
|
|
err = (ch.get("oauth_error") or "").replace("\n"," ")[:120]
|
|
print(
|
|
f"{name} | oauth_ok={ch.get('oauth_ok')} | profile={ch.get('oauth_profile_id')} | "
|
|
f"rt={bool(ch.get('refresh_token'))} | err={err!r} | checked={ch.get('oauth_checked_at')}"
|
|
)
|
|
|
|
chs = db.list_shorts_channels()
|
|
bad=[c for c in chs if int(c.get('oauth_ok') if c.get('oauth_ok') is not None else -1)==0]
|
|
print("bad_count", len(bad), "/", len(chs))
|
|
for c in bad:
|
|
err=(c.get("oauth_error") or "").replace("\n"," ")[:140]
|
|
print(" BAD", c.get("name"), "|", err, "| profile", c.get("oauth_profile_id"))
|
|
PY
|
|
'''
|
|
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect("107.173.30.245", 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_probe_oauth2.sh", "w") as f:
|
|
f.write(REMOTE)
|
|
sftp.close()
|
|
_, o, e = c.exec_command("bash /tmp/_probe_oauth2.sh", timeout=60)
|
|
out = (o.read() + e.read()).decode("utf-8", "replace")
|
|
open(r"c:\Users\admin\Desktop\douyinWEB\scripts\_oauth_probe_out.txt", "w", encoding="utf-8").write(out)
|
|
print(out)
|
|
c.close()
|