"""Fetch Hong Kong public holiday data from 1823.gov.hk.""" import datetime import requests # Traditional Chinese names, consistent with CN data format HK_ICAL_URL = "https://www.1823.gov.hk/common/ical/tc.json" # Earliest year available from the 1823.gov.hk API HK_START_YEAR = 2024 def fetch_hk_holiday(year: int) -> dict: """Fetch HK public holidays for a given year. HK has no makeup work day (调休) concept, so all entries are isOffDay=True. Data coverage starts from HK_START_YEAR. """ response = requests.get(HK_ICAL_URL) response.raise_for_status() data = response.json() events = data["vcalendar"][0]["vevent"] days = [] for event in events: dtstart = event["dtstart"][0] # "YYYYMMDD" date = datetime.date(int(dtstart[:4]), int(dtstart[4:6]), int(dtstart[6:8])) if date.year != year: continue days.append( { "name": event["summary"], "date": date.isoformat(), "isOffDay": True, } ) days.sort(key=lambda d: d["date"]) return { "year": year, "papers": [HK_ICAL_URL], "days": days, }