feat: 从卡片文本提取智能纪要标题
This commit is contained in:
@ -16,6 +16,7 @@ AI_NOTES_CHAT_ID = "7391681490647744513"
|
||||
AI_NOTES_URL_RE = re.compile(
|
||||
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]:
|
||||
@ -35,6 +36,12 @@ def resolve_calendar_links(config: dict[str, Any]) -> dict[str, str]:
|
||||
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(
|
||||
client: Any,
|
||||
target_day: date,
|
||||
@ -69,13 +76,15 @@ def fetch_ai_notes_links(
|
||||
{"chat_id": chat_id, "start": start_ts, "end": end_ts},
|
||||
)
|
||||
for content, content_data, ts in result:
|
||||
# Search content and content_data separately to avoid mixing with JSON
|
||||
for text_to_search in (str(content or ""), str(content_data or "")):
|
||||
text = str(content 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):
|
||||
url = match.group(0)
|
||||
if url not in seen_urls:
|
||||
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:
|
||||
pass # Fall back to network if storage read fails
|
||||
|
||||
@ -133,7 +142,10 @@ def _fetch_ai_notes_links_from_network(
|
||||
if ts:
|
||||
batch_min_time = ts if batch_min_time is None else min(batch_min_time, ts)
|
||||
if start_ts <= ts < end_ts:
|
||||
content = str(msg.get("content") or "")
|
||||
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:
|
||||
# Extract URLs with topics from raw content_data
|
||||
extracted = storage._extract_links_with_topics(content_data)
|
||||
@ -141,17 +153,15 @@ def _fetch_ai_notes_links_from_network(
|
||||
url = item["url"]
|
||||
if url not in seen_urls:
|
||||
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:
|
||||
# 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
|
||||
for match in AI_NOTES_URL_RE.finditer(text_to_search):
|
||||
url = match.group(0)
|
||||
if url not in seen_urls:
|
||||
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:
|
||||
break
|
||||
upper = lower - 1
|
||||
|
||||
Reference in New Issue
Block a user