nomadro/apps/miniprogram/weapp/scripts/_strip_oa_qr_tt.py
eric 3e5b7c2098 Monorepo super-optimize: src layout, workspace scripts, docs.
Collapse portal under src/, unify pnpm workspace/scripts, thin VIP topic re-exports, drop orphan vip scaffolds and one-shot scripts, ignore xhs/release, document root commands.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-01 00:34:04 +08:00

58 lines
2.1 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.

# -*- coding: utf-8 -*-
"""One-shot: strip WeChat OA QR / 引流文案 from tt book data (Douyin audit)."""
from __future__ import annotations
import re
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
OA_QR_IMG_RE = re.compile(r"!\[[^\]]*\]\([^)]*qrcode_for_gh[^)]*\)\s*", re.I)
# real newlines OR escaped \\n inside TS/JSON string literals
OA_LINE_RE = re.compile(
r"(?:^|(?<=\\n)|(?<=\n))[>\s]*公众号\s*[::][^\n\\]*(?:\\n|\n)?",
)
OA_PLACEHOLDER_RE = re.compile(
r"(?:^|(?<=\\n)|(?<=\n))[>\s]*(?:<!--\s*)?🖼\s*(配图已省略\s*·\s*完整图见公众号「[^」]*」)\s*(?:-->)?(?:\\n|\n)?"
)
OA_INLINE_RE = re.compile(
r"关注公众号[^·\\\"\\\n]*|完整大图见公众号「[^」]*」|完整图见公众号「[^」]*」|看本公众号`?同名账号`?"
)
def sanitize(s: str) -> str:
s = OA_QR_IMG_RE.sub("", s)
s = OA_LINE_RE.sub("", s)
s = OA_PLACEHOLDER_RE.sub("", s)
s = OA_INLINE_RE.sub("", s)
s = s.replace("关注公众号异度世界 · 私信加群", "数字游民 · 离线精选")
s = s.replace('"tagline": "· 私信加群"', '"tagline": "数字游民 · 离线精选"')
s = s.replace('"tagline": " · 私信加群"', '"tagline": "数字游民 · 离线精选"')
s = re.sub(r"(?:\\n){3,}", r"\\n\\n", s)
s = re.sub(r"\n{3,}", "\n\n", s)
return s
def main() -> None:
for rel in ("tt/src/data/nomadCodeBook.ts", "tt/src/data/coverBook.ts"):
p = ROOT / rel
raw = p.read_text(encoding="utf-8")
out = sanitize(raw)
p.write_text(out, encoding="utf-8")
print(
rel,
"changed" if out != raw else "unchanged",
"qrcode=",
"qrcode_for_gh" in out,
"oa_line=",
("公众号: 异度" in out or "公众号:异度" in out),
"公众号 in content=",
"公众号" in out,
"tagline_bad=",
"私信加群" in out and "数字游民" not in out.split("tagline")[1][:40] if "tagline" in out else False,
)
if __name__ == "__main__":
main()