From 3cf70481409928794fe4f60b64bfcbf072bfcc4d Mon Sep 17 00:00:00 2001 From: wangyunlong <3080433063@qq.com> Date: Tue, 27 Oct 2026 10:10:33 +0800 Subject: [PATCH] =?UTF-8?q?fix(content-marketing):=20=E7=AC=94=E8=AE=B0?= =?UTF-8?q?=E6=A0=87=E9=A2=98=E5=85=A5=E5=BA=93=E5=89=8D=E5=89=A5=E9=99=A4?= =?UTF-8?q?=E8=AF=9D=E9=A2=98=E9=93=BE=E6=8E=A5=E6=AE=B5=E4=B8=8E=E8=A3=B8?= =?UTF-8?q?=20URL?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 登记人常把抖音「复制分享文案」整段粘进发布笔记标题列,含 [话题](url) 链接段(个别为 {url} 花括号包裹)和裸 URL。新增 clean_note_title: 剥链接后非空则采用;整段皆链接时取方括号内话题文本去重拼接; 仍为空则保留原文兜底,避免标题落空。 --- .../data/tools/sync_notes_master.py | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/gyxx_flow/modules/content_marketing/data/tools/sync_notes_master.py b/src/gyxx_flow/modules/content_marketing/data/tools/sync_notes_master.py index 0da03a3..ceac953 100644 --- a/src/gyxx_flow/modules/content_marketing/data/tools/sync_notes_master.py +++ b/src/gyxx_flow/modules/content_marketing/data/tools/sync_notes_master.py @@ -219,6 +219,36 @@ def parse_wan_count(text: str) -> int | None: return None +# 抖音"复制分享文案"格式:标题 + 话题链接段 [话题](url)(个别登记写成了 {url} 花括号包裹), +# 或裸 URL。登记人常把整段分享文案粘进「发布笔记标题」列,入库前剥掉链接只留标题文本。 +_TITLE_LINK_RE = re.compile( + r"\[[^\]]*\]\([^)]*\)" # [text](url) 圆括号链接 + r"|\[[^\]]*\]\{[^}]*\}" # [text]{url} 花括号链接 + r"|\{https?://[^}]*\}" # {url} 裸花括号链接 + r"|https?://[^\s))\]]+" # 裸 URL +) + + +def clean_note_title(raw: str) -> str: + """剥掉标题里混入的话题链接段与裸 URL,只留标题文本。 + + 兜底顺序:剥链接后非空 → 用它;整段都是链接(标题只剩话题/搜索词)→ + 取方括号内的文本去重拼接;再不行 → 保留原文,避免落空。 + """ + text = raw or "" + cleaned = _TITLE_LINK_RE.sub("", text) + cleaned = cleaned.replace("%20", " ") # 链接段之间残留的 URL 编码空格 + cleaned = re.sub(r"\s{2,}", " ", cleaned).strip() + if cleaned: + return cleaned + inner = [t.strip() for t in re.findall(r"\[([^\]]*)\]", text)] + seen: list[str] = [] + for item in inner: + if item and item not in seen: + seen.append(item) + return " ".join(seen) if seen else text.strip() + + def normalize_publish_time(cell: Any) -> str | None: text = cell_text(cell) if not text: @@ -340,7 +370,7 @@ def parse_records( record_id=record_id, platform=resolve_platform(value(record, "platform"), url), creator_name=creator_name, - title=cell_text(value(record, "note_title"))[:512], + title=clean_note_title(cell_text(value(record, "note_title")))[:512], publish_time=normalize_publish_time(value(record, "publish_time")), url=url, creator_attrs=creator_attrs,