P2: print→logging 전환, 포트폴리오 중복 제거, Docker healthcheck 추가
- backend/main.py: logging 모듈 도입, print() 제거 - stock-lab/main.py: print() → logger 전환, _calc_portfolio_totals 공용 함수 추출 - stock-lab/scraper.py: logging 모듈 도입, print() 제거 - docker-compose.yml: 전 서비스 healthcheck 블록 추가 (30s 간격, 3회 재시도) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
import logging
|
||||
import requests
|
||||
from bs4 import BeautifulSoup
|
||||
from typing import List, Dict, Any
|
||||
import time
|
||||
|
||||
logger = logging.getLogger("stock-lab.scraper")
|
||||
|
||||
# 네이버 파이낸스 주요 뉴스
|
||||
NAVER_FINANCE_NEWS_URL = "https://finance.naver.com/news/mainnews.naver"
|
||||
# 해외증시 뉴스 (모바일 API 사용)
|
||||
@@ -73,7 +76,7 @@ def fetch_market_news() -> List[Dict[str, str]]:
|
||||
return articles
|
||||
|
||||
except Exception as e:
|
||||
print(f"[StockLab] Scraping failed: {e}")
|
||||
logger.error(f"국내 뉴스 스크래핑 실패: {e}")
|
||||
return []
|
||||
|
||||
def fetch_overseas_news() -> List[Dict[str, str]]:
|
||||
@@ -126,7 +129,7 @@ def fetch_overseas_news() -> List[Dict[str, str]]:
|
||||
return articles
|
||||
|
||||
except Exception as e:
|
||||
print(f"[StockLab] Overseas news failed: {e}")
|
||||
logger.error(f"해외 뉴스 스크래핑 실패: {e}")
|
||||
return []
|
||||
|
||||
def fetch_major_indices() -> Dict[str, Any]:
|
||||
@@ -237,7 +240,7 @@ def fetch_major_indices() -> Dict[str, Any]:
|
||||
})
|
||||
|
||||
except Exception as e:
|
||||
print(f"[StockLab] World indices failed: {e}")
|
||||
logger.error(f"해외 지수 스크래핑 실패: {e}")
|
||||
|
||||
# --- 환율 (USD/KRW) ---
|
||||
try:
|
||||
@@ -269,10 +272,10 @@ def fetch_major_indices() -> Dict[str, Any]:
|
||||
"type": "exchange"
|
||||
})
|
||||
except Exception as e:
|
||||
print(f"[StockLab] Exchange rate failed: {e}")
|
||||
logger.error(f"환율 스크래핑 실패: {e}")
|
||||
|
||||
return {"indices": indices, "crawled_at": time.strftime("%Y-%m-%d %H:%M:%S")}
|
||||
|
||||
except Exception as e:
|
||||
print(f"[StockLab] Indices scraping failed: {e}")
|
||||
logger.error(f"지수 스크래핑 전체 실패: {e}")
|
||||
return {"indices": [], "error": str(e)}
|
||||
|
||||
Reference in New Issue
Block a user