fix(home): serve today's starlanguage from daily guidance
The homepage was waiting on a full chart plus four extra engines, so the card timed out and showed the failure copy on every visit. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -78,26 +78,39 @@ def _moon_transit(reference_date: str, tz: float, ayanamsa: str) -> dict[str, An
|
||||
}
|
||||
|
||||
|
||||
def _current_dasha(chart: dict[str, Any], reference_date: str) -> dict[str, Any]:
|
||||
def _current_mahadasha(chart: dict[str, Any], body: dict[str, Any], reference_date: str) -> str | None:
|
||||
birth = chart.get("birth_info") or {}
|
||||
moon = (chart.get("planets") or {}).get("Moon") or {}
|
||||
moon_lon = moon.get("lon", moon.get("degree_raw", moon.get("degree")))
|
||||
try:
|
||||
birth_dt = datetime(
|
||||
_safe_int(birth.get("year")),
|
||||
_safe_int(birth.get("month"), 1),
|
||||
_safe_int(birth.get("day"), 1),
|
||||
_safe_int(birth.get("hour")),
|
||||
_safe_int(birth.get("minute")),
|
||||
_safe_int(birth.get("second")),
|
||||
_safe_int(body.get("year"), _safe_int(birth.get("year"))),
|
||||
_safe_int(body.get("month"), _safe_int(birth.get("month"), 1)),
|
||||
_safe_int(body.get("day"), _safe_int(birth.get("day"), 1)),
|
||||
_safe_int(body.get("hour"), _safe_int(birth.get("hour"))),
|
||||
_safe_int(body.get("minute"), _safe_int(birth.get("minute"))),
|
||||
_safe_int(body.get("second"), _safe_int(birth.get("second"))),
|
||||
)
|
||||
return compute_vimshottari_timeline(
|
||||
timeline = compute_vimshottari_timeline(
|
||||
birth_dt=birth_dt,
|
||||
moon_lon=float(moon_lon),
|
||||
current_date=datetime.strptime(reference_date[:10], "%Y-%m-%d"),
|
||||
).get("current_dasha") or {}
|
||||
except Exception as exc:
|
||||
return {"status": "blocked", "reason": str(exc)}
|
||||
)
|
||||
except Exception:
|
||||
return None
|
||||
periods = timeline.get("periods") if isinstance(timeline, dict) else None
|
||||
if isinstance(periods, list):
|
||||
for period in periods:
|
||||
if not isinstance(period, dict):
|
||||
continue
|
||||
start = str(period.get("start") or "")
|
||||
end = str(period.get("end") or "")
|
||||
lord = period.get("lord")
|
||||
if start and end and start <= reference_date <= end and lord:
|
||||
return str(lord)
|
||||
balance = timeline.get("birth_balance") if isinstance(timeline, dict) else None
|
||||
lord = balance.get("lord") if isinstance(balance, dict) else None
|
||||
return str(lord) if lord else None
|
||||
|
||||
|
||||
def build_daily_guidance(body: dict[str, Any]) -> dict[str, Any]:
|
||||
@@ -110,8 +123,9 @@ def build_daily_guidance(body: dict[str, Any]) -> dict[str, Any]:
|
||||
moon_transit = _moon_transit(reference_date, tz, ayanamsa)
|
||||
moon_house = _house_from_sign(asc_sign, moon_transit.get("sign"))
|
||||
theme, action = HOUSE_THEMES.get(moon_house or 0, ("今日", "整理计划、稳步推进"))
|
||||
dasha = _current_dasha(chart, reference_date)
|
||||
dasha_lord = dasha.get("mahadasha_lord") or dasha.get("lord") or dasha.get("md_lord")
|
||||
dasha_lord = _current_mahadasha(chart, body, reference_date)
|
||||
natal_moon = (chart.get("planets") or {}).get("Moon") or {}
|
||||
natal_moon_sign = natal_moon.get("sign") if isinstance(natal_moon, dict) else None
|
||||
evidence = [
|
||||
{
|
||||
"layer": "D1",
|
||||
@@ -136,6 +150,13 @@ def build_daily_guidance(body: dict[str, Any]) -> dict[str, Any]:
|
||||
"success": True,
|
||||
"endpoint": "daily_guidance",
|
||||
"date": reference_date,
|
||||
"theme": theme,
|
||||
"theme_action": action,
|
||||
"moon_house": moon_house,
|
||||
"moon_sign": moon_transit.get("sign"),
|
||||
"natal_moon_sign": natal_moon_sign,
|
||||
"ascendant_sign": asc_sign,
|
||||
"mahadasha_lord": dasha_lord,
|
||||
"daily_star_words": text,
|
||||
"word_count": len(text),
|
||||
"suggested_actions": [item.strip() for item in action.split("、")],
|
||||
|
||||
Reference in New Issue
Block a user