73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Set Shorts gap settings to 10min via API; report quota board. Do not toggle shorts_enabled."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import http.cookiejar
|
|
import urllib.request
|
|
|
|
sys.stdout.reconfigure(encoding="utf-8", errors="replace")
|
|
|
|
|
|
def session(base: str):
|
|
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)
|
|
return op
|
|
|
|
|
|
def call(op, base, path, method="GET", body=None, timeout=40):
|
|
data = None if body is None else json.dumps(body).encode()
|
|
req = urllib.request.Request(
|
|
base + path,
|
|
data=data,
|
|
method=method,
|
|
headers={"Content-Type": "application/json"} if body is not None else {},
|
|
)
|
|
with op.open(req, timeout=timeout) as r:
|
|
return json.loads(r.read().decode())
|
|
|
|
|
|
for base in ("https://dy.nomadro.com", "https://dylive.nomadro.com"):
|
|
print(f"\n===== {base} =====")
|
|
op = session(base)
|
|
before = call(op, base, "/api/shorts/status")
|
|
print(
|
|
"before enabled=", before.get("enabled"),
|
|
"ch_gap=", before.get("channel_min_gap_sec"),
|
|
"up_gap=", before.get("upload_min_gap_sec"),
|
|
"board_gap=", (before.get("board") or {}).get("total_gap"),
|
|
"min_unmet=", (before.get("board") or {}).get("min_unmet"),
|
|
)
|
|
# Only change gap rules — never flip shorts_enabled here.
|
|
patched = call(
|
|
op,
|
|
base,
|
|
"/api/settings",
|
|
method="PATCH",
|
|
body={
|
|
"shorts_channel_min_gap_sec": 600,
|
|
"shorts_upload_min_gap_sec": 600,
|
|
"shorts_dedupe_room_day": True,
|
|
},
|
|
)
|
|
print("patched keys ok=", bool(patched))
|
|
after = call(op, base, "/api/shorts/status")
|
|
print(
|
|
"after enabled=", after.get("enabled"),
|
|
"ch_gap=", after.get("channel_min_gap_sec"),
|
|
"up_gap=", after.get("upload_min_gap_sec"),
|
|
)
|
|
board = after.get("board") or {}
|
|
chans = board.get("channels") or []
|
|
unmet = [c for c in chans if c.get("enabled") and not c.get("min_met")]
|
|
print("min_unmet_count=", len(unmet), "total_gap=", board.get("total_gap"), "push_date=", board.get("push_date"))
|
|
for c in unmet[:8]:
|
|
print(" ", c.get("name"), "used=", c.get("used"), "min=", c.get("daily_min"), "max=", c.get("daily_max"))
|
|
print("done")
|