89 lines
2.9 KiB
Python
89 lines
2.9 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Re-arm Client B API cool-down with Pacific date so sync won't wipe it."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import time
|
|
import http.cookiejar
|
|
import urllib.request
|
|
from datetime import datetime, timezone, timedelta
|
|
from pathlib import Path
|
|
|
|
import paramiko
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
pt = datetime.fromtimestamp(time.time(), tz=timezone(timedelta(hours=-7))).strftime("%Y-%m-%d")
|
|
|
|
REMOTE = f"""#!/bin/bash
|
|
set -euo pipefail
|
|
python3 <<'PY'
|
|
import sqlite3, json, time
|
|
conn = sqlite3.connect("/opt/douyinWEB/backend/data/monitor.db")
|
|
raw = conn.execute("SELECT value FROM kv_settings WHERE key=?", ("shorts_yt_quota_by_profile",)).fetchone()
|
|
qmap = json.loads(raw[0]) if raw and raw[0] else {{}}
|
|
now = time.time()
|
|
pt = {pt!r}
|
|
until = now + 3600
|
|
e = dict(qmap.get("B") or {{}})
|
|
e["date"] = pt
|
|
e["blocked_until"] = until
|
|
e["quota_ntfy_at"] = now
|
|
e["count"] = max(int(e.get("count") or 0), 90)
|
|
qmap["B"] = e
|
|
conn.execute(
|
|
"INSERT INTO kv_settings(key,value) VALUES(?,?) "
|
|
"ON CONFLICT(key) DO UPDATE SET value=excluded.value",
|
|
("shorts_yt_quota_by_profile", json.dumps(qmap, ensure_ascii=False)),
|
|
)
|
|
conn.commit()
|
|
print("armed", qmap["B"])
|
|
conn.close()
|
|
PY
|
|
systemctl restart douyinweb-api.service
|
|
sleep 5
|
|
systemctl is-active douyinweb-api.service
|
|
"""
|
|
|
|
|
|
def deploy(label, host, port, user, pw, *, sudo):
|
|
print(f"===== {label} =====")
|
|
c = paramiko.SSHClient()
|
|
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
|
|
c.connect(host, port, user, pw, timeout=45, allow_agent=False, look_for_keys=False)
|
|
sftp = c.open_sftp()
|
|
with sftp.file("/tmp/_dy_rearm_b.sh", "w") as f:
|
|
f.write(REMOTE.replace("\r\n", "\n"))
|
|
sftp.close()
|
|
cmd = f"echo '{pw}' | sudo -S -p '' bash /tmp/_dy_rearm_b.sh" if sudo else "bash /tmp/_dy_rearm_b.sh"
|
|
_, o, e = c.exec_command(cmd, timeout=120)
|
|
print((o.read() + e.read()).decode("utf-8", "replace"))
|
|
c.close()
|
|
|
|
|
|
def pub(base):
|
|
cj = http.cookiejar.CookieJar()
|
|
op = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(cj))
|
|
data = json.dumps({"username": "hackrobot", "password": "Xiao4669805@"}).encode()
|
|
req = urllib.request.Request(
|
|
base + "/api/auth/login", data=data, method="POST", headers={"Content-Type": "application/json"}
|
|
)
|
|
op.open(req, timeout=30)
|
|
with op.open(urllib.request.Request(base + "/api/shorts/status"), timeout=40) as r:
|
|
st = json.loads(r.read().decode())
|
|
print(
|
|
base,
|
|
"blocked=", st.get("upload_quota_blocked"),
|
|
"profiles=", st.get("upload_quota_blocked_profiles"),
|
|
"until=", st.get("upload_quota_blocked_until"),
|
|
"B=", next((p for p in (st.get("yt_quota_by_profile") or []) if p.get("id") == "B"), None),
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# Only dylive had recent B 429 spam
|
|
deploy("VPS dylive", "107.173.30.245", 22, "root", "Xiao4669805", sudo=False)
|
|
pub("https://dylive.nomadro.com")
|
|
pub("https://dy.nomadro.com")
|