from datetime import datetime import httpx from services.external.data_go_kr import get_all_items HOLIDAY_URL = "https://apis.data.go.kr/B090041/openapi/service/SpcdeInfoService/getRestDeInfo" async def fetch_holidays(client: httpx.AsyncClient, year: int, month: int) -> list[dict]: items = await get_all_items(client, HOLIDAY_URL, {"_type": "json", "solYear": year, "solMonth": f"{month:02d}"}, page_size=50) return [ {"holiday_date": datetime.strptime(str(it["locdate"]), "%Y%m%d").date(), "name": it["dateName"][:20]} for it in items if it.get("isHoliday") == "Y" ] SOLAR_TERM_URL = "https://apis.data.go.kr/B090041/openapi/service/SpcdeInfoService/get24DivisionsInfo" async def fetch_solar_terms(client: httpx.AsyncClient, year: int, month: int) -> list[dict]: items = await get_all_items(client, SOLAR_TERM_URL, {"_type": "json", "solYear": year, "solMonth": f"{month:02d}"}, page_size=10) return [{"term_date": datetime.strptime(str(it["locdate"]), "%Y%m%d").date(), "name": it["dateName"][:10]} for it in items]