Files
stock_chart_site/backend/app/pipelines/daily_batch.py
tkrmagid 56f73a1f12 feat(phase-1a): external data fetchers + refresh pipeline + scheduler
10종목 시드 + pykrx OHLCV / 외인·기관 거래대금, KIS read-only EOD, OpenDART
공시, 네이버 금융 뉴스 스크레이퍼, 구글 뉴스 RSS, yfinance 거시(KOSPI/KOSDAQ/
USDKRW/US10Y) fetcher 를 추가하고 refresh_one / daily_batch / backfill /
APScheduler(16:00 KST) 파이프라인으로 묶음.

- backend/app/seed: 10종목 시드 (대형/고변동/테마/플랫폼/방어)
- backend/app/fetch: pykrx, kis, dart, news, macro, symbols_seed
- backend/app/pipelines: refresh_one, daily_batch, backfill(CLI), scheduler
- backend/app/api/refresh.py: POST /api/refresh/{code}?lookback_days=N
- backend/app/main.py: lifespan 으로 스케줄러 기동/종료, /health/keys 추가
- README: .env 복사 안내 보강

스모크 테스트 (실제 키 사용) 결과:
  KIS token  : ok (token 346자 발급)
  KIS daily  : 005930 11rows
  DART list  : 005930 30일 10건
  Naver news : 005930 12건
  Google RSS : "삼성전자" 92건

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-20 15:43:18 +09:00

47 lines
1.3 KiB
Python

"""일별 배치: 16:00 KST 에 시드 10종목 + 거시 + 뉴스 + DART 갱신.
수동 실행:
python -m app.pipelines.daily_batch
"""
from __future__ import annotations
import json
import logging
import time
from typing import Any
from app.fetch import macro as macro_mod
from app.pipelines.refresh_one import refresh_code
from app.seed.seed_tickers import SEED_TICKERS
logger = logging.getLogger(__name__)
def run_daily_batch() -> dict[str, Any]:
start_ts = time.time()
reports: list[dict[str, Any]] = []
for t in SEED_TICKERS:
logger.info("daily_batch refresh %s %s", t.code, t.name)
rep = refresh_code(t.code, t.name, lookback_days=7)
reports.append(rep.to_dict())
macros = macro_mod.fetch_macro_daily(years=1)
macro_summary = [
{"key": m.key, "status": m.status(), "inserted": m.inserted,
"updated": m.updated, "error": m.error}
for m in macros
]
elapsed = time.time() - start_ts
return {
"duration_seconds": round(elapsed, 2),
"tickers": reports,
"macro": macro_summary,
}
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO, format="%(asctime)s %(levelname)s %(name)s: %(message)s")
out = run_daily_batch()
print(json.dumps(out, ensure_ascii=False, indent=2, default=str))