nomadro/apps/miniprogram/weapp/scripts/_check_book_json.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

42 lines
937 B
Python

# -*- coding: utf-8 -*-
import json
from pathlib import Path
s = Path("apps/miniprogram/weapp/src/data/nomadCodeBook.ts").read_text(encoding="utf-8")
key = "chapters: "
i = s.index(key)
j = s.index("[", i)
depth = 0
end = -1
in_str = False
esc = False
quote = ""
for k in range(j, len(s)):
c = s[k]
if in_str:
if esc:
esc = False
elif c == "\\":
esc = True
elif c == quote:
in_str = False
continue
if c in "\"'":
in_str = True
quote = c
continue
if c == "[":
depth += 1
elif c == "]":
depth -= 1
if depth == 0:
end = k
break
try:
arr = json.loads(s[j : end + 1])
print("chapters", len(arr), "first", arr[0]["title"], "bodyLen", len(arr[0].get("content") or ""))
print("last", arr[-1]["title"])
except Exception as e:
print("FAIL", e)
print(s[j : j + 120])