- Add scripts/fetch_hk.py to fetch HK holidays from 1823.gov.hk
- Make generate_ics() cal_name/cal_desc configurable
- Refactor update.py with REGIONS config; support --region cn|hk flag
- Generate hk/{year}.json and hk/{year}.ics under hk/ subdirectory
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
"""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,
|
|
}
|