feat: 从卡片文本提取智能纪要标题
This commit is contained in:
@ -16,6 +16,7 @@ AI_NOTES_CHAT_ID = "7391681490647744513"
|
|||||||
AI_NOTES_URL_RE = re.compile(
|
AI_NOTES_URL_RE = re.compile(
|
||||||
r"https://[A-Za-z0-9.-]+\.feishu\.cn/(?:docx|minutes)/[A-Za-z0-9]+(?:\?[^\s\x00-\x1f]*)?"
|
r"https://[A-Za-z0-9.-]+\.feishu\.cn/(?:docx|minutes)/[A-Za-z0-9]+(?:\?[^\s\x00-\x1f]*)?"
|
||||||
)
|
)
|
||||||
|
TOPIC_RE = re.compile(r"Topic:\s*([^\n]+?)(?=Owner:|\Z)")
|
||||||
|
|
||||||
|
|
||||||
def resolve_calendar_links(config: dict[str, Any]) -> dict[str, str]:
|
def resolve_calendar_links(config: dict[str, Any]) -> dict[str, str]:
|
||||||
@ -35,6 +36,12 @@ def resolve_calendar_links(config: dict[str, Any]) -> dict[str, str]:
|
|||||||
return resolved
|
return resolved
|
||||||
|
|
||||||
|
|
||||||
|
def _extract_topic(text: str) -> str:
|
||||||
|
"""Extract a meeting topic from card text like 'Topic: 标题Owner: ...'."""
|
||||||
|
match = TOPIC_RE.search(text or "")
|
||||||
|
return match.group(1).strip() if match else ""
|
||||||
|
|
||||||
|
|
||||||
def fetch_ai_notes_links(
|
def fetch_ai_notes_links(
|
||||||
client: Any,
|
client: Any,
|
||||||
target_day: date,
|
target_day: date,
|
||||||
@ -69,13 +76,15 @@ def fetch_ai_notes_links(
|
|||||||
{"chat_id": chat_id, "start": start_ts, "end": end_ts},
|
{"chat_id": chat_id, "start": start_ts, "end": end_ts},
|
||||||
)
|
)
|
||||||
for content, content_data, ts in result:
|
for content, content_data, ts in result:
|
||||||
# Search content and content_data separately to avoid mixing with JSON
|
text = str(content or "")
|
||||||
for text_to_search in (str(content or ""), str(content_data or "")):
|
data_text = str(content_data or "")
|
||||||
|
topic = _extract_topic(text) or _extract_topic(data_text)
|
||||||
|
for text_to_search in (text, data_text):
|
||||||
for match in AI_NOTES_URL_RE.finditer(text_to_search):
|
for match in AI_NOTES_URL_RE.finditer(text_to_search):
|
||||||
url = match.group(0)
|
url = match.group(0)
|
||||||
if url not in seen_urls:
|
if url not in seen_urls:
|
||||||
seen_urls.add(url)
|
seen_urls.add(url)
|
||||||
links.append({"url": url, "create_time": int(ts), "topic": ""})
|
links.append({"url": url, "create_time": int(ts), "topic": topic})
|
||||||
except Exception:
|
except Exception:
|
||||||
pass # Fall back to network if storage read fails
|
pass # Fall back to network if storage read fails
|
||||||
|
|
||||||
@ -133,7 +142,10 @@ def _fetch_ai_notes_links_from_network(
|
|||||||
if ts:
|
if ts:
|
||||||
batch_min_time = ts if batch_min_time is None else min(batch_min_time, ts)
|
batch_min_time = ts if batch_min_time is None else min(batch_min_time, ts)
|
||||||
if start_ts <= ts < end_ts:
|
if start_ts <= ts < end_ts:
|
||||||
|
content = str(msg.get("content") or "")
|
||||||
content_data = msg.get("content_data")
|
content_data = msg.get("content_data")
|
||||||
|
content_data_str = str(content_data or "")
|
||||||
|
topic = _extract_topic(content) or _extract_topic(content_data_str)
|
||||||
if content_data and storage is not None:
|
if content_data and storage is not None:
|
||||||
# Extract URLs with topics from raw content_data
|
# Extract URLs with topics from raw content_data
|
||||||
extracted = storage._extract_links_with_topics(content_data)
|
extracted = storage._extract_links_with_topics(content_data)
|
||||||
@ -141,17 +153,15 @@ def _fetch_ai_notes_links_from_network(
|
|||||||
url = item["url"]
|
url = item["url"]
|
||||||
if url not in seen_urls:
|
if url not in seen_urls:
|
||||||
seen_urls.add(url)
|
seen_urls.add(url)
|
||||||
links.append({"url": url, "create_time": ts, "topic": item.get("topic", "")})
|
links.append({"url": url, "create_time": ts, "topic": topic or item.get("topic", "")})
|
||||||
else:
|
else:
|
||||||
# Fallback to plain text search
|
# Fallback to plain text search
|
||||||
content = str(msg.get("content") or "")
|
|
||||||
content_data_str = str(content_data or "")
|
|
||||||
text_to_search = content + content_data_str
|
text_to_search = content + content_data_str
|
||||||
for match in AI_NOTES_URL_RE.finditer(text_to_search):
|
for match in AI_NOTES_URL_RE.finditer(text_to_search):
|
||||||
url = match.group(0)
|
url = match.group(0)
|
||||||
if url not in seen_urls:
|
if url not in seen_urls:
|
||||||
seen_urls.add(url)
|
seen_urls.add(url)
|
||||||
links.append({"url": url, "create_time": ts, "topic": ""})
|
links.append({"url": url, "create_time": ts, "topic": topic})
|
||||||
if batch_min_time and batch_min_time < start_ts:
|
if batch_min_time and batch_min_time < start_ts:
|
||||||
break
|
break
|
||||||
upper = lower - 1
|
upper = lower - 1
|
||||||
|
|||||||
@ -1,7 +1,49 @@
|
|||||||
from datetime import date
|
from datetime import date, datetime
|
||||||
from zoneinfo import ZoneInfo
|
from zoneinfo import ZoneInfo
|
||||||
|
|
||||||
from snooper_calendar import fetch_calendar_events
|
from snooper_calendar import (
|
||||||
|
AI_NOTES_CHAT_ID,
|
||||||
|
_extract_topic,
|
||||||
|
fetch_ai_notes_links,
|
||||||
|
fetch_calendar_events,
|
||||||
|
)
|
||||||
|
from snooper_storage import SnifferStorage
|
||||||
|
|
||||||
|
|
||||||
|
def test_extract_topic_from_card_text():
|
||||||
|
text = (
|
||||||
|
"[卡片]\nMeeting recording completed"
|
||||||
|
"Topic: 指数-金科定期AI业务讨论会Owner: 万轶伦"
|
||||||
|
)
|
||||||
|
assert _extract_topic(text) == "指数-金科定期AI业务讨论会"
|
||||||
|
assert _extract_topic("https://efund.feishu.cn/docx/abc") == ""
|
||||||
|
|
||||||
|
|
||||||
|
def test_fetch_ai_notes_links_reads_topic_from_local_content():
|
||||||
|
tz = ZoneInfo("Asia/Shanghai")
|
||||||
|
storage = SnifferStorage(url="sqlite:///:memory:")
|
||||||
|
ts = int(datetime(2026, 11, 17, 14, 0, tzinfo=tz).timestamp())
|
||||||
|
storage.save_message({
|
||||||
|
"msg_id": "minutes-1",
|
||||||
|
"chat_id": AI_NOTES_CHAT_ID,
|
||||||
|
"chat_type": 2,
|
||||||
|
"from_id": "bot",
|
||||||
|
"msg_type": 14,
|
||||||
|
"create_time": ts,
|
||||||
|
"content": (
|
||||||
|
"[卡片]\nMeeting recording completed"
|
||||||
|
"Topic: 指数-金科定期AI业务讨论会Owner: 万轶伦\n"
|
||||||
|
"https://efund.feishu.cn/minutes/abc123"
|
||||||
|
),
|
||||||
|
})
|
||||||
|
|
||||||
|
links = fetch_ai_notes_links(
|
||||||
|
object(), date(2026, 11, 17), tz, storage=storage
|
||||||
|
)
|
||||||
|
|
||||||
|
assert len(links) == 1
|
||||||
|
assert links[0]["url"].startswith("https://efund.feishu.cn/minutes/abc123")
|
||||||
|
assert links[0]["topic"] == "指数-金科定期AI业务讨论会"
|
||||||
|
|
||||||
|
|
||||||
class FakeCalendarClient:
|
class FakeCalendarClient:
|
||||||
|
|||||||
Reference in New Issue
Block a user