Add daily Feishu digest for dota2.refining.dev traffic.

Gitea Actions runs notify_site_traffic.py at 09:00 CST using Cloudflare GraphQL and a Feishu webhook (secrets from keyzoo).

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
voson
2026-07-28 15:26:07 +08:00
co-authored by Cursor
parent 9898dd39fb
commit 9f484166d4
6 changed files with 755 additions and 65 deletions
+68
View File
@@ -0,0 +1,68 @@
"""Two-pass keyzoo helper: stash Feishu URL then run notify with Cloudflare.
Pass 1 (feishu asset): python _notify_pass_feishu.py stash
Pass 2 (cloudflare): python _notify_pass_feishu.py run [--day ...] [--dry-run]
Temp file is user-only and deleted after run.
"""
from __future__ import annotations
import argparse
import os
import stat
import sys
from pathlib import Path
STASH = Path(os.environ.get("TEMP") or os.environ.get("TMP") or ".") / "climperor_feishu_wh.url"
def stash() -> None:
url = os.environ.get("KEYZOO_ASSET_SECRET_FEISHU_WEBHOOK_URL") or os.environ.get(
"FEISHU_WEBHOOK_URL"
)
if not url:
raise SystemExit("no feishu webhook in env")
STASH.write_text(url, encoding="utf-8")
try:
os.chmod(STASH, stat.S_IRUSR | stat.S_IWUSR)
except OSError:
pass
print(f"stashed webhook -> {STASH.name} ({STASH.exists()})")
def run(argv: list[str]) -> int:
if not STASH.exists():
raise SystemExit(f"missing stash {STASH}; run pass1 first")
url = STASH.read_text(encoding="utf-8").strip()
try:
STASH.unlink()
except OSError:
pass
os.environ["FEISHU_WEBHOOK_URL"] = url
# Import after env is set
import notify_site_traffic as n
return n.main(argv)
def main() -> int:
ap = argparse.ArgumentParser()
ap.add_argument("cmd", choices=("stash", "run"))
ap.add_argument("--day")
ap.add_argument("--dry-run", action="store_true")
args, rest = ap.parse_known_args()
if args.cmd == "stash":
stash()
return 0
argv: list[str] = []
if args.day:
argv += ["--day", args.day]
if args.dry_run:
argv += ["--dry-run"]
argv += rest
return run(argv)
if __name__ == "__main__":
raise SystemExit(main())