refactor: 전체 코드베이스 감사 기반 리팩토링 — 버그 수정, 데드코드 제거, 보안 강화
P0 버그 수정: - stock-lab: trade 엔드포인트 NameError 수정 (resp 미정의) - deployer: 동시 배포 시 HTTP 200 → 503 반환 P1 데드코드 제거: - stock-lab: fetch_overseas_news(), get_broker_cash() 제거 - blog-lab: 미사용 urlparse import 제거 - lotto-lab: 중복 inline import json 7곳 제거 P2 성능/효율 개선: - lotto-lab: 가중 샘플링 3중 복사 → utils.weighted_sample_6() 통합 - lotto-lab: DB 인덱스 3개 추가 (recommendations, purchase_history) - stock-lab: Pydantic .dict() → .model_dump() 호환 - blog-lab: 페이지네이션 상한(le=100) 추가 P3 보안/인프라: - nginx: X-Frame-Options, X-Content-Type-Options, Referrer-Policy 헤더 추가 - docker-compose: travel-proxy CORS 와일드카드 → localhost 전용 - Dockerfile: music-lab, blog-lab, realestate-lab에 PYTHONUNBUFFERED 추가 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -79,59 +79,6 @@ def fetch_market_news() -> List[Dict[str, str]]:
|
||||
logger.error(f"국내 뉴스 스크래핑 실패: {e}")
|
||||
return []
|
||||
|
||||
def fetch_overseas_news() -> List[Dict[str, str]]:
|
||||
"""
|
||||
네이버 금융 해외증시 뉴스 크롤링 (모바일 API 사용)
|
||||
"""
|
||||
api_url = "https://api.stock.naver.com/news/overseas/mainnews"
|
||||
try:
|
||||
headers = {
|
||||
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)"
|
||||
}
|
||||
resp = requests.get(api_url, headers=headers, timeout=10)
|
||||
resp.raise_for_status()
|
||||
|
||||
data = resp.json()
|
||||
if isinstance(data, list):
|
||||
items = data
|
||||
else:
|
||||
items = data.get("result", [])
|
||||
|
||||
articles = []
|
||||
for item in items:
|
||||
# API 키 매핑 (subject/title/tit, summary/subContent/sub_tit 등)
|
||||
title = item.get("subject") or item.get("title") or item.get("tit") or ""
|
||||
summary = item.get("summary") or item.get("subContent") or item.get("sub_tit") or ""
|
||||
press = item.get("officeName") or item.get("office_name") or item.get("cp_name") or ""
|
||||
|
||||
# 날짜 포맷팅 (20260126123000 -> 2026-01-26 12:30:00)
|
||||
raw_dt = str(item.get("dt", ""))
|
||||
if len(raw_dt) == 14:
|
||||
date = f"{raw_dt[:4]}-{raw_dt[4:6]}-{raw_dt[6:8]} {raw_dt[8:10]}:{raw_dt[10:12]}:{raw_dt[12:]}"
|
||||
else:
|
||||
date = raw_dt
|
||||
|
||||
# 링크 생성
|
||||
aid = item.get("articleId")
|
||||
oid = item.get("officeId")
|
||||
link = f"https://m.stock.naver.com/worldstock/news/read/{oid}/{aid}"
|
||||
|
||||
articles.append({
|
||||
"title": title,
|
||||
"link": link,
|
||||
"summary": summary,
|
||||
"press": press,
|
||||
"date": date,
|
||||
"crawled_at": time.strftime("%Y-%m-%d %H:%M:%S"),
|
||||
"category": "overseas"
|
||||
})
|
||||
|
||||
return articles
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"해외 뉴스 스크래핑 실패: {e}")
|
||||
return []
|
||||
|
||||
def fetch_major_indices() -> Dict[str, Any]:
|
||||
"""
|
||||
KOSPI, KOSDAQ, KOSPI200 등 주요 지표 (네이버 금융 홈)
|
||||
|
||||
Reference in New Issue
Block a user