토너먼트 대진 추가
This commit is contained in:
1 parent
59db1c4e9a
commit
6815540ae6
6 files changed
+161
-50
No files matched your search
@@ -23,6 +23,17 @@ from ..teams_data import code_for_tla
|
||||
log = logging.getLogger("triplepick.schedule")
|
||||
|
||||
KST = timezone(timedelta(hours=9))
|
||||
|
||||
# football-data stage → 녹아웃 라운드 라벨(한글). 조별리그는 group 으로 따로 처리.
|
||||
# 2026 포맷(48개국)은 32강(LAST_32)부터 토너먼트가 시작된다.
|
||||
KO_STAGE_LABEL = {
|
||||
"LAST_32": "32강",
|
||||
"LAST_16": "16강",
|
||||
"QUARTER_FINALS": "8강",
|
||||
"SEMI_FINALS": "4강",
|
||||
"THIRD_PLACE": "3·4위전",
|
||||
"FINAL": "결승",
|
||||
}
|
||||
# "13:00 UTC-6" / "20:00 UTC+2" 형태 파싱
|
||||
_TIME_RE = re.compile(r"(\d{1,2}):(\d{2})\s*UTC\s*([+-]\d{1,2})")
|
||||
|
||||
@@ -97,9 +108,12 @@ async def _fetch_football_data() -> list[dict]:
|
||||
|
||||
|
||||
async def _fetch_all_groups_football_data() -> list[dict]:
|
||||
"""football-data 에서 전체 조별리그(12개조 72경기) 수집.
|
||||
"""football-data 에서 전체 조별리그 + 녹아웃 토너먼트 일정 수집.
|
||||
|
||||
반환: [{teamA, teamB, group('A'..'L'), kickoffKst, venue}] (tla→코드)
|
||||
반환: [{teamA, teamB, group('A'..'L' 또는 ''), roundLabel('' 또는 '32강'..), kickoffKst, venue}]
|
||||
조별리그는 group 으로, 32강 이후 토너먼트는 roundLabel 로 구분한다(tla→코드).
|
||||
녹아웃 경기는 대진이 확정되기 전엔 팀이 TBD 라 소스가 tla 를 주지 않아 자동 제외되고,
|
||||
조별리그 종료로 대진이 확정되면 다음 동기화에서 자동 등장한다.
|
||||
"""
|
||||
if not settings.football_data_token:
|
||||
log.warning("schedule(all): football-data 토큰 미설정 — 수집 생략")
|
||||
@@ -117,13 +131,19 @@ async def _fetch_all_groups_football_data() -> list[dict]:
|
||||
|
||||
out: list[dict] = []
|
||||
for m in data.get("matches", []):
|
||||
if m.get("stage") != "GROUP_STAGE":
|
||||
continue
|
||||
g = (m.get("group") or "").replace("GROUP_", "") # 'A'..'L'
|
||||
stage = m.get("stage")
|
||||
if stage == "GROUP_STAGE":
|
||||
g = (m.get("group") or "").replace("GROUP_", "") # 'A'..'L'
|
||||
round_label = ""
|
||||
elif stage in KO_STAGE_LABEL:
|
||||
g = "" # 녹아웃은 조 없음 — roundLabel 로 구분
|
||||
round_label = KO_STAGE_LABEL[stage]
|
||||
else:
|
||||
continue # 예선/플레이오프 등은 제외
|
||||
ht = (m.get("homeTeam") or {}).get("tla")
|
||||
at = (m.get("awayTeam") or {}).get("tla")
|
||||
if not ht or not at:
|
||||
continue
|
||||
continue # 대진 미확정(TBD) — 확정 후 다음 동기화에서 등장
|
||||
utc = m.get("utcDate")
|
||||
if not utc:
|
||||
continue
|
||||
@@ -135,6 +155,7 @@ async def _fetch_all_groups_football_data() -> list[dict]:
|
||||
"teamA": code_for_tla(ht),
|
||||
"teamB": code_for_tla(at),
|
||||
"group": g,
|
||||
"roundLabel": round_label,
|
||||
"kickoffKst": kickoff,
|
||||
"venue": m.get("venue") or "",
|
||||
}
|
||||
@@ -232,7 +253,12 @@ async def _results_football_data() -> list[dict]:
|
||||
ft = ((m.get("score") or {}).get("fullTime") or {})
|
||||
if ft.get("home") is None or ft.get("away") is None:
|
||||
continue
|
||||
out.append({"teamA": a, "teamB": b, "scoreA": int(ft["home"]), "scoreB": int(ft["away"])})
|
||||
# 라운드 표기 — 같은 두 팀이 조별리그·토너먼트에서 만나도 정산을 구분(없으면 "").
|
||||
round_label = KO_STAGE_LABEL.get(m.get("stage") or "", "")
|
||||
out.append({
|
||||
"teamA": a, "teamB": b, "scoreA": int(ft["home"]), "scoreB": int(ft["away"]),
|
||||
"roundLabel": round_label,
|
||||
})
|
||||
return out
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user