Files
daily-robots/daily/text_utils.py
yumao 6ea2a4e4c6 feat: 早报系统重构与功能增强
- 新增常驻调度器 daily/scheduler.py + run-scheduler.ps1(定时生成/推送)
- 新增 daily/bridge_manager.py:Windows 兼容的 Cursor SDK 桥接
- 新增 skills/daily-featured-pick 首推 Skill 与叙事轴/去重逻辑
- 新闻抓取窗口、GitHub 搜索、企微 delta 模式等多项改进
- 补充设计文档与 superpowers 计划/规范
- 新增对应测试(scheduler、featured_pick、github_search、news_fetch_window 等)

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-17 18:12:00 +08:00

39 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 re
_WS = re.compile(r"\s+")
def clip_text(text: str, limit: int) -> str:
text = _WS.sub(" ", (text or "").strip())
if limit <= 0 or len(text) <= limit:
return text
return text[: max(1, limit - 1)] + ""
def trim_brief(text: str, limit: int) -> str:
"""企微简要:控制在 limit 内,优先在句读/词边界截断,不加省略号。"""
text = _WS.sub(" ", (text or "").strip())
if not text or limit <= 0 or len(text) <= limit:
return text
for sep in ("", "", "", ""):
pos = text.find(sep)
if pos != -1 and pos + 1 <= limit + 8:
return text[: pos + 1]
for sep in ("", ""):
pos = text.find(sep)
if pos != -1 and pos + 1 <= limit:
return text[: pos + 1]
for sep in (". ", "! ", "? ", "; "):
pos = text.rfind(sep, 0, limit + 1)
if pos != -1 and pos + 1 >= min(limit // 2, 20):
return text[: pos + 1].rstrip()
if len(text) > limit:
space = text.rfind(" ", 0, limit + 1)
if space >= min(limit // 2, 20):
return text[:space].rstrip(",、;: ,.;")
return text[:limit].rstrip(",、;: ,.;")