feat: 新增企微早报推送闸门判定逻辑

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-07-09 11:35:49 +08:00
parent e3b5623860
commit b2dd8721d0

51
daily/push_gate.py Normal file
View File

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