chore: 恢复开发文档全目录进库并同步阅读页与脚本改动
Made-with: Cursor
This commit is contained in:
@@ -8,7 +8,9 @@
|
||||
SOUL_TEST_ENV=soulapi python3 scripts/content_download.py --id 10.27
|
||||
python3 scripts/content_download.py 128 --out-dir /path/to/2026每日派对干货
|
||||
|
||||
2026 场次(第102场起)对应 id 10.01、10.02、…、10.27(第128场)…
|
||||
2026 每日派对章节挂在 part-2026-02 / part-2026-03 / part-2026-04 等篇章下,
|
||||
业务 id(如 10.34)与「第 N 场」不是简单线性公式;若按场次推算 404,脚本会
|
||||
自动在上述 part 里按 sectionTitle「第N场」解析真实 id。
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
@@ -34,15 +36,40 @@ DEFAULT_BOOK_2026 = Path(
|
||||
|
||||
|
||||
def field_to_id(field: int) -> str:
|
||||
"""第 N 场(≥102)→ 10.xx;第101场及以前在第九章为 9.xx。API 上第128场可能为 9.28。"""
|
||||
"""首猜 id:≥102 用 10.(field-102+1);与线上一致性不保证,404 时会走 resolve。"""
|
||||
if field >= 102:
|
||||
n = field - 102 + 1
|
||||
return f"10.{n:02d}"
|
||||
if field >= 1:
|
||||
return f"9.{field:02d}" # 第9章 9.01~9.99,按场次
|
||||
return f"9.{field:02d}"
|
||||
raise ValueError("场次请用 1~999")
|
||||
|
||||
|
||||
def resolve_2026_chapter_id_by_field(base: str, field: int, requests_mod) -> str | None:
|
||||
"""在 part-2026-* 下按标题「第N场」查真实 chapters.id。"""
|
||||
parts_url = f"{base}/api/miniprogram/book/parts"
|
||||
pr = requests_mod.get(parts_url, timeout=30)
|
||||
if pr.status_code != 200:
|
||||
return None
|
||||
pdata = pr.json()
|
||||
parts = pdata.get("parts") or []
|
||||
needle = f"第{field}场"
|
||||
for p in parts:
|
||||
pid = p.get("id") or ""
|
||||
if not pid.startswith("part-2026-"):
|
||||
continue
|
||||
url = f"{base}/api/miniprogram/book/chapters-by-part?partId={pid}"
|
||||
cr = requests_mod.get(url, timeout=30)
|
||||
if cr.status_code != 200:
|
||||
continue
|
||||
cdata = cr.json().get("data") or []
|
||||
for row in cdata:
|
||||
title = row.get("sectionTitle") or ""
|
||||
if needle in title:
|
||||
return row.get("id")
|
||||
return None
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="从小程序 API 下载单章为 md")
|
||||
parser.add_argument("field", nargs="?", type=int, help="场次号,如 128 表示第128场")
|
||||
@@ -83,6 +110,13 @@ def main():
|
||||
r = requests.get(url, timeout=30)
|
||||
if r.status_code == 200:
|
||||
chapter_id = fallback_id
|
||||
if r.status_code == 404 and args.field is not None and not args.id:
|
||||
resolved = resolve_2026_chapter_id_by_field(base, args.field, requests)
|
||||
if resolved:
|
||||
chapter_id = resolved
|
||||
url = f"{base}/api/miniprogram/book/chapter/by-id/{chapter_id}"
|
||||
print(f"404,按 2026 篇章标题解析到 id: {chapter_id} | GET {url}")
|
||||
r = requests.get(url, timeout=30)
|
||||
r.raise_for_status()
|
||||
data = r.json()
|
||||
if not data.get("success"):
|
||||
|
||||
Reference in New Issue
Block a user