Capture Neko/WG/network hubs, Studio viewer charts, physical deploy docs, and one-shot scripts so VPS vs physical can be toggled later without losing WIP. Co-authored-by: Cursor <cursoragent@cursor.com>
103 lines
3.3 KiB
Python
103 lines
3.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Probe all Shorts OAuth + retry monetize on nomad vlog test video."""
|
|
from __future__ import annotations
|
|
|
|
import asyncio
|
|
import json
|
|
import sys
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
HOST = "107.173.30.245"
|
|
REPO = "/opt/douyinWEB"
|
|
|
|
REMOTE = r"""
|
|
import asyncio, json
|
|
from app import db
|
|
from app import shorts_oauth
|
|
from app import yt_long_monetize
|
|
from app.shorts_oauth import channel_oauth_creds
|
|
|
|
async def main():
|
|
rows = []
|
|
for ch in db.list_shorts_channels(enabled=None):
|
|
cid = str(ch.get("id") or "")
|
|
if not str(ch.get("refresh_token") or "").strip():
|
|
rows.append({"name": ch.get("name"), "ok": False, "err": "no_token"})
|
|
continue
|
|
r = await shorts_oauth.probe_channel_oauth(ch)
|
|
scopes = []
|
|
try:
|
|
from app.shorts_upload import refresh_access_token
|
|
from app.shorts_oauth import channel_oauth_creds, token_scopes
|
|
creds = channel_oauth_creds(ch)
|
|
if creds.get("refresh_token"):
|
|
access = await refresh_access_token(
|
|
client_id=str(creds["client_id"]),
|
|
client_secret=str(creds["client_secret"]),
|
|
refresh_token=str(creds["refresh_token"]),
|
|
)
|
|
scopes = sorted(await token_scopes(str(access)))
|
|
except Exception:
|
|
pass
|
|
rows.append({
|
|
"name": ch.get("name"),
|
|
"ok": r.get("ok"),
|
|
"err": r.get("error", ""),
|
|
"force_ssl": any("force-ssl" in s for s in scopes),
|
|
})
|
|
ok = sum(1 for x in rows if x.get("ok"))
|
|
bad = [x for x in rows if not x.get("ok")]
|
|
print("OAUTH_PROBE", ok, "ok", len(bad), "bad")
|
|
for x in bad:
|
|
print(" BAD", x.get("name"), "-", (x.get("err") or "")[:140])
|
|
no_ssl = [x for x in rows if x.get("ok") is False and "force-ssl" in str(x.get("err") or "")]
|
|
if no_ssl:
|
|
print("MISSING_FORCE_SSL", len(no_ssl))
|
|
|
|
target = None
|
|
for ch in db.list_shorts_channels(enabled=None):
|
|
n = str(ch.get("name") or "").lower()
|
|
if "nomad vlog" in n or "nomadvlog" in n:
|
|
target = ch
|
|
break
|
|
if not target:
|
|
print("NO_NOMAD_VLOG")
|
|
return
|
|
creds = channel_oauth_creds(target)
|
|
from app import yt_long_db
|
|
long_row = yt_long_db.get_yt_long_by_shorts_pk(str(target.get("id") or ""))
|
|
r = await yt_long_monetize.ensure_ypp_and_monetize(
|
|
client_id=str(creds["client_id"]),
|
|
client_secret=str(creds["client_secret"]),
|
|
refresh_token=str(creds["refresh_token"]),
|
|
video_id="ch1MMlZMfU0",
|
|
channel_row=long_row or target,
|
|
force_monetize=True,
|
|
)
|
|
print("MONETIZE_RETRY", json.dumps(r, ensure_ascii=False)[:600])
|
|
|
|
asyncio.run(main())
|
|
"""
|
|
|
|
|
|
def main() -> None:
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(HOST, 22, "root", "Xiao4669805", timeout=30, allow_agent=False, look_for_keys=False)
|
|
_, out, err = c.exec_command(
|
|
f"cd {REPO}/backend && .venv/bin/python - <<'PY'\n{REMOTE}\nPY",
|
|
timeout=180,
|
|
)
|
|
print(out.read().decode("utf-8", "replace"))
|
|
e = err.read().decode("utf-8", "replace").strip()
|
|
if e:
|
|
print("STDERR:", e[:1000])
|
|
c.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|