auto: 일일 백업 2026-09-11 02:00
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -222,20 +222,34 @@ def cmd_sync(years_forward: int) -> int:
|
||||
# 양쪽 다 0건이면 영구 변경/네트워크 차단 의심 — health 카운트 + 2회 연속 시 알림.
|
||||
both_failed = (not investing_data) and (not nager_data_raw)
|
||||
_update_health(both_failed, errors)
|
||||
if not investing_data:
|
||||
sys.stderr.write('no holidays parsed — investing.com 미반영. state file은 옛 데이터 유지.\n')
|
||||
if not investing_data and not nager_data_raw:
|
||||
sys.stderr.write('no holidays parsed — 두 소스 모두 실패. state file은 옛 데이터 유지.\n')
|
||||
return 3
|
||||
# KRX는 다음 연도 휴장 캘린더를 보통 11~12월에 공식 발표 → 그 전엔 investing.com도 비어 있음.
|
||||
# investing이 한 건이라도 잡은 연도에만 nager 보강 — 미발표 연도의 일반 공휴일이 KRX 휴장으로 잘못 등록되는 것 차단.
|
||||
investing_years = {int(d[:4]) for d in investing_data}
|
||||
nager_data = {d: n for d, n in nager_data_raw.items() if int(d[:4]) in investing_years}
|
||||
# 채울 연도 판정. KRX는 다음 연도 휴장 캘린더를 보통 11~12월에 공식 발표하므로,
|
||||
# 미발표 연도의 일반 공휴일을 KRX 휴장으로 잘못 등록하지 않도록 게이트를 둔다.
|
||||
# - investing(거래소 캘린더)이 살아 있으면 그게 곧 발표 신호 → 그 연도만 채운다(원래 규칙).
|
||||
# - investing이 죽었으면(2026-09 이후 403 차단) 달력으로 대신 판정 — 올해는 항상,
|
||||
# 내년은 11월 이후에만. 이래야 12월→1월 갭도 막고 미발표 연도도 오염되지 않는다.
|
||||
if investing_data:
|
||||
allowed_years = {int(d[:4]) for d in investing_data}
|
||||
else:
|
||||
now = datetime.now(KST)
|
||||
allowed_years = {now.year} | ({now.year + 1} if now.month >= 11 else set())
|
||||
nager_data = {d: n for d, n in nager_data_raw.items() if int(d[:4]) in allowed_years}
|
||||
# investing.com(거래소 캘린더) 우선 — KRX 휴장 권위. nager는 누락분만 채움.
|
||||
holidays = {**nager_data, **investing_data}
|
||||
nager_extra = sorted(d for d in nager_data if d not in investing_data)
|
||||
# nager는 '공휴일'이라 거래소 전용 휴장인 연말 폐장일(12/31)이 없다. 평일일 때만 보강.
|
||||
for y in sorted(allowed_years):
|
||||
eoy = date(y, 12, 31)
|
||||
key = eoy.isoformat()
|
||||
if eoy.weekday() < 5 and key not in holidays:
|
||||
holidays[key] = '연말 휴장'
|
||||
STATE_FILE.parent.mkdir(parents=True, exist_ok=True)
|
||||
payload = {
|
||||
'fetched_at': datetime.now(KST).isoformat(),
|
||||
'sources': {'primary': URL, 'fallback': NAGER_URL.format(year='YYYY')},
|
||||
'source_used': 'investing+nager' if investing_data else 'nager-only',
|
||||
'years': years,
|
||||
'holidays': dict(sorted(holidays.items())),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user