feat: 静默日跳过企微 webhook 推送

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-09 11:37:55 +08:00
parent 588def8eb2
commit 3ad2e7c090

View File

@@ -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}")