From b2dd8721d01ae961125c1f5831dfea8787d42a7b Mon Sep 17 00:00:00 2001 From: yumao Date: Thu, 9 Jul 2026 11:35:49 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E4=BC=81=E5=BE=AE?= =?UTF-8?q?=E6=97=A9=E6=8A=A5=E6=8E=A8=E9=80=81=E9=97=B8=E9=97=A8=E5=88=A4?= =?UTF-8?q?=E5=AE=9A=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Cursor --- daily/push_gate.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 daily/push_gate.py diff --git a/daily/push_gate.py b/daily/push_gate.py new file mode 100644 index 0000000..b360de6 --- /dev/null +++ b/daily/push_gate.py @@ -0,0 +1,51 @@ +"""企微早报推送闸门。""" + +from __future__ import annotations + +from dataclasses import dataclass, field +from typing import Any + +from daily.config import force_push, skip_push_when_silent + + +@dataclass +class PushGateResult: + should_push: bool + reasons: list[str] = field(default_factory=list) + silent: bool = False + + +def _has_board_moves(movement: dict[str, Any]) -> bool: + keys = ( + "skills_trending_moves", + "skills_hot_moves", + "github_trending_moves", + "github_emerging_moves", + "github_topic_moves", + ) + return any(movement.get(k) for k in keys) + + +def evaluate_push_gate( + *, + movement: dict[str, Any], + ai_news_items: list[dict[str, Any]], + cn_ai_news_items: list[dict[str, Any]], + featured_pick: dict[str, Any] | None, +) -> PushGateResult: + if force_push(): + return PushGateResult(should_push=True, reasons=["force_push"], silent=False) + + reasons: list[str] = [] + if _has_board_moves(movement): + reasons.append("board_moves") + if ai_news_items: + reasons.append("ai_news") + if cn_ai_news_items: + reasons.append("cn_ai_news") + if featured_pick: + reasons.append("featured_pick") + + should = bool(reasons) + silent = not should and skip_push_when_silent() + return PushGateResult(should_push=should, reasons=reasons, silent=silent)