From 3ad2e7c090bff9372ab638505bf318594989e172 Mon Sep 17 00:00:00 2001 From: yumao Date: Thu, 9 Jul 2026 11:37:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=9D=99=E9=BB=98=E6=97=A5=E8=B7=B3?= =?UTF-8?q?=E8=BF=87=E4=BC=81=E5=BE=AE=20webhook=20=E6=8E=A8=E9=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- daily/webhook.py | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/daily/webhook.py b/daily/webhook.py index ba4e8da..13f820b 100644 --- a/daily/webhook.py +++ b/daily/webhook.py @@ -2,6 +2,8 @@ from __future__ import annotations +import json +import re import sys import time from pathlib import Path @@ -13,6 +15,7 @@ from daily.config import OUTPUT_DIR, ROOT, env_int, wecom_chunk_bytes from daily.wecom_split import split_wecom_messages _PUSH_GAP_MS = 300 +_DATE_RE = re.compile(r"(\d{4}-\d{2}-\d{2})\.wecom\.md$") def _load_webhook_key() -> str: @@ -43,6 +46,31 @@ def _resolve_report_path(arg: str | None) -> Path: raise RuntimeError("未找到 .wecom.md 报告,请先运行 python -m daily") +def _push_gate_for_report(path: Path) -> dict | None: + match = _DATE_RE.search(path.name) + if not match: + return None + data_path = path.parent / f"{match.group(1)}.data.json" + if not data_path.exists(): + data_path = OUTPUT_DIR / f"{match.group(1)}.data.json" + if not data_path.exists(): + return None + try: + payload = json.loads(data_path.read_text(encoding="utf-8")) + except (OSError, ValueError): + return None + meta = payload.get("meta") or {} + gate = meta.get("push_gate") + return gate if isinstance(gate, dict) else None + + +def should_skip_push(report_path: Path) -> bool: + gate = _push_gate_for_report(report_path) + if not gate: + return False + return bool(gate.get("silent")) and not gate.get("should_push") + + def _post_markdown(client: httpx.Client, url: str, content: str) -> None: payload = {"msgtype": "markdown", "markdown": {"content": content}} resp = client.post(url, json=payload) @@ -54,6 +82,9 @@ def _post_markdown(client: httpx.Client, url: str, content: str) -> None: def send_report(report_path: Path | None = None) -> None: path = _resolve_report_path(str(report_path) if report_path else None) + if should_skip_push(path): + print(f"[silent] no push gate matched for {path.name}") + return if not path.exists(): raise RuntimeError(f"报告文件不存在: {path}")