diff --git a/backend/app/services/baseball_fetch.py b/backend/app/services/baseball_fetch.py index 2711aaf..2483529 100644 --- a/backend/app/services/baseball_fetch.py +++ b/backend/app/services/baseball_fetch.py @@ -95,17 +95,24 @@ async def _fetch_mlb(days_back: int, days_ahead: int) -> list[dict]: kickoff = ( datetime.fromisoformat(gd.replace("Z", "+00:00")).astimezone(KST) ) - state = (g.get("status") or {}).get("detailedState", "") + status_obj = g.get("status") or {} + # detailedState 는 "Final"/"Game Over"/"Completed Early"(우천 조기종료) 등 + # 종료를 뜻하는 문자열이 여러 갈래라 그것만으로 판정하면 일부가 누락된다. + # abstractGameState 는 Preview/Live/Final 세 값만 존재하는 신뢰 가능한 판정 기준. + abstract = status_obj.get("abstractGameState", "") + detailed = status_obj.get("detailedState", "") rec = { "league": "mlb", "teamA": a, "teamB": b, "dateKst": kickoff.strftime("%Y%m%d"), "kickoffKst": kickoff.isoformat(), "venue": (g.get("venue") or {}).get("name", ""), - "cancelled": state in ("Postponed", "Cancelled", "Suspended"), + "cancelled": abstract != "Final" and detailed.startswith( + ("Postponed", "Cancelled", "Suspended") + ), "gamePk": g.get("gamePk"), # MLB 라이브 피드 키 } - if state == "Final" and not rec["cancelled"]: + if abstract == "Final" and not rec["cancelled"]: sa = g["teams"]["away"].get("score") sb = g["teams"]["home"].get("score") if sa is not None and sb is not None: