Files
daily-robots/daily/board_select.py
2026-07-14 10:32:39 +08:00

47 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""五榜唯一列表主人:周去重 + 深池补满。"""
from __future__ import annotations
import logging
from typing import Any, Literal
from daily.delta import skill_id
logger = logging.getLogger(__name__)
def board_select(
*,
board: str,
items: list[dict[str, Any]],
recent_keys: set[str],
limit: int,
pool_size: int,
kind: Literal["skill", "github"],
) -> list[dict[str, Any]]:
"""从深池过滤近 N 日已展示 key按原顺序取满 limit不足则短榜。"""
if kind == "skill":
from daily.skills_group import group_skills_by_source
pool = group_skills_by_source(items, limit=pool_size, pool_size=pool_size)
def key_fn(x: dict[str, Any]) -> str:
return skill_id(x)
else:
pool = items[: max(pool_size, limit)]
def key_fn(x: dict[str, Any]) -> str:
return str(x.get("repo") or "")
out: list[dict[str, Any]] = []
for item in pool:
k = key_fn(item)
if not k or k in recent_keys:
continue
out.append(item)
if len(out) >= limit:
break
if len(out) < limit:
logger.info("board_short:%s:%s", board, len(out))
return out