Files
Jyotisha/scripts/report_render/dasha_reference.py
T
ClaudeandClaude Opus 5.5 223c90ca0c
Independent Staging Quality Gate / validate-frontend (push) Successful in 6m20s
Independent Staging Quality Gate / validate-python (push) Successful in 7m37s
Independent Staging Quality Gate / publish (push) Successful in 2m47s
fix(report): drop the remaining 「来源」 lines and print birth-data source codes as reader words (BUG-2115 follow-up)
Annual clock captions no longer end with "this report's native calculation";
the general dasha reference drops its per-lord study-notes citation; the birth
data section translates user_reported / family_exact and the other stored codes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXp2U3BH1SxwAGyhhbe1
2026-11-21 11:35:24 +08:00

83 lines
3.9 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.
"""「大运传统参考」: nine Mahadasha lords, three paragraphs each, both editions.
Text: `references/mahadasha_editorial_bilingual.json`, synced from the
astrologer's skill repository (yinduzhanxing 058c4f5f, 2026-11-06). Rules:
`references/mahadasha_editorial_policy.md`.
- A general reference, the three paragraphs side by side. Nothing here picks
「有利」 or 「压力」 for this chart, and nothing says the reader is afflicted.
- Mahadasha lord layer only; no Mahadasha/Antardasha combinations.
- The source is secondary study notes; the page markers are not BPHS edition
pages, and the report says so. The English edition shows English only.
"""
from __future__ import annotations
import json
import re
from functools import lru_cache
from pathlib import Path
_PATH = Path(__file__).resolve().parents[2] / "references" / "mahadasha_editorial_bilingual.json"
_KINDS = (
("general", "一般背景", "General background"),
("supportive_conditions", "传统有利条件下", "Under traditionally supportive conditions"),
("strained_conditions", "传统压力条件下", "Under traditionally strained conditions"),
)
_HAN = re.compile(r"[一-鿿]")
@lru_cache(maxsize=1)
def load_reference() -> dict:
with _PATH.open(encoding="utf-8") as handle:
return json.load(handle)
def render_dasha_reference(language: str) -> str:
data = load_reference()
zh = language == "zh"
lines = [
"## 大运传统参考(通用)" if zh else "## Traditional Dasha Reference (general)",
"",
(
"下面是九颗大运主星在传统文本里的通用主题,三段并列。哪一段更贴近这张盘,"
"要看功能吉凶、宫主与落宫、尊贵、力量、燃烧、相照与缓解因素,本章不替这张盘做判断,也不是推算结果。"
"只写大运主星这一层,不拼接小运。"
) if zh else (
"Traditional themes for each of the nine Mahadasha lords, the three paragraphs side by side. "
"Which one is closer to this chart depends on functional roles, house lordship and placement, dignity, "
"strength, combustion, aspects and mitigating factors; this chapter does not decide that for the chart "
"and is not a calculated result. It covers the Mahadasha lord only, not sub-period combinations."
),
"",
]
for planet in data.get("planets") or []:
if not isinstance(planet, dict):
continue
name = planet.get("name_zh") if zh else planet.get("id")
paragraphs = {item.get("kind"): item for item in planet.get("paragraphs") or [] if isinstance(item, dict)}
if not name or not all(kind in paragraphs for kind, _zh, _en in _KINDS):
continue
lines.extend([f"### {name}", ""])
for kind, label_zh, label_en in _KINDS:
item = paragraphs[kind]
text = str(item.get("zh" if zh else "en") or "").strip()
if not text or (not zh and _HAN.search(text)):
continue
lines.extend([f"**{label_zh if zh else label_en}**:{text}" if zh else f"**{label_en}**: {text}", ""])
# BUG-2115 (负责人 2026-11-21): no 「来源:《BPHS 读书笔记》…」 line under each lord; the pages stay in the data file.
return "\n".join(lines).rstrip() + "\n"
def insert_dasha_reference(markdown: str, language: str) -> str:
"""Right after the 「大运解释」 / Dasha Interpretation chapter; unchanged when it is absent."""
if not markdown:
return markdown
heading = r"^## (?:大运解释|Dasha Interpretation)\s*$"
match = re.search(heading, markdown, flags=re.MULTILINE)
if not match:
return markdown
following = re.search(r"^## ", markdown[match.end():], flags=re.MULTILINE)
cut = match.end() + following.start() if following else len(markdown)
return markdown[:cut].rstrip() + "\n\n" + render_dasha_reference(language).rstrip() + "\n\n" + markdown[cut:].lstrip()