feat(mls): MLS 리그 추가 — ESPN 비공식 API 연동
- 일정·결과·컨퍼런스 순위·프리뷰(폼/시즌전적/맞대결/머니라인) 수집 - 라이브 카드: 스코어·경기시간·득점/카드·선발 라인업(피치 뷰)·교체 현황 - 문자중계: ESPN commentary 규칙 기반 한글 변환 (미지원 템플릿은 팀명만 한글화) - MLS 레코드는 야구와 키 구조가 같아 sync_baseball_schedule/settle 재사용 - AI 예측 데이터 블록에 MLS 전용 컨텍스트 추가 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
ad5bbec82e
commit
74de57fc1c
22 files changed
+1723
-83
No files matched your search
@@ -57,10 +57,14 @@ async def get_live(
|
||||
match_id: str,
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> dict:
|
||||
"""야구 라이브 필드 뷰 (kbo=네이버 relay, mlb=공식 feed/live). 15초 TTL 캐시."""
|
||||
"""라이브 뷰 (kbo=네이버 relay, mlb=공식 feed/live, mls=ESPN). 15초 TTL 캐시."""
|
||||
m = await db.get(Match, match_id)
|
||||
if not m:
|
||||
raise HTTPException(status_code=404, detail="MATCH_NOT_FOUND")
|
||||
if m.league == "mls":
|
||||
from ..services.mls_espn import fetch_live_mls
|
||||
|
||||
return await fetch_live_mls(m)
|
||||
if m.league not in ("kbo", "mlb"):
|
||||
return {"available": False}
|
||||
return await fetch_live(m)
|
||||
@@ -1,6 +1,7 @@
|
||||
"""리그 순위표 API — 워커가 캐싱한 standings:{league} 를 팀 정보와 합쳐 서빙.
|
||||
|
||||
KBO: 단일 테이블(10팀, 순위순). MLB: 디비전(AL/NL × 동·중·서) 6그룹.
|
||||
MLS: 컨퍼런스(동/서부) 2그룹 — 승점제.
|
||||
캐시가 아직 없으면 빈 groups 를 반환한다(프론트는 안내 문구 표시).
|
||||
"""
|
||||
from __future__ import annotations
|
||||
@@ -16,14 +17,16 @@ router = APIRouter(prefix="/api/standings", tags=["standings"])
|
||||
|
||||
# MLB 디비전 표시 순서 (AL 동→중→서, NL 동→중→서)
|
||||
_MLB_DIV_ORDER = ["ALE", "ALC", "ALW", "NLE", "NLC", "NLW"]
|
||||
# MLS 컨퍼런스 표시 순서 (동부 → 서부)
|
||||
_MLS_CONF_ORDER = ["EAST", "WEST"]
|
||||
|
||||
|
||||
@router.get("")
|
||||
async def get_standings(
|
||||
league: str = Query(..., description="kbo | mlb"),
|
||||
league: str = Query(..., description="kbo | mlb | mls"),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
) -> dict:
|
||||
if league not in ("kbo", "mlb"):
|
||||
if league not in ("kbo", "mlb", "mls"):
|
||||
return {"league": league, "updatedAt": None, "groups": []}
|
||||
row = await db.get(DataCache, f"standings:{league}")
|
||||
table: dict = row.payload if row else {}
|
||||
@@ -32,6 +35,15 @@ async def get_standings(
|
||||
if league == "kbo":
|
||||
rows.sort(key=lambda r: r.get("rank") or 99)
|
||||
groups = [{"key": None, "rows": rows}] if rows else []
|
||||
elif league == "mls":
|
||||
by_conf: dict[str, list] = {}
|
||||
for r in rows:
|
||||
by_conf.setdefault(r.get("div") or "", []).append(r)
|
||||
for lst in by_conf.values():
|
||||
lst.sort(key=lambda r: r.get("rank") or 99)
|
||||
groups = [
|
||||
{"key": c, "rows": by_conf[c]} for c in _MLS_CONF_ORDER if c in by_conf
|
||||
]
|
||||
else:
|
||||
by_div: dict[str, list] = {}
|
||||
for r in rows:
|
||||
|
||||
Reference in new issue
Block a user