Spaces:
Runtime error
Runtime error
Update main.py
Browse files
main.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
from fastapi import FastAPI, HTTPException, Query
|
| 2 |
import uvicorn
|
| 3 |
from pydantic import BaseModel
|
|
@@ -22,7 +23,6 @@ from functools import lru_cache
|
|
| 22 |
from fastapi.middleware.cors import CORSMiddleware
|
| 23 |
import traceback
|
| 24 |
from datetime import datetime, timedelta
|
| 25 |
-
from googletrans import Translator
|
| 26 |
from starlette.concurrency import run_in_threadpool
|
| 27 |
import FinanceDataReader as fdr
|
| 28 |
from groq import Groq
|
|
@@ -36,16 +36,13 @@ logger = logging.getLogger(__name__)
|
|
| 36 |
|
| 37 |
API_KEY = os.getenv("Groq_API_KEY")
|
| 38 |
|
| 39 |
-
|
| 40 |
if not API_KEY:
|
| 41 |
# API 키가 없으면 에러를 발생시키거나 경고
|
| 42 |
-
print("
|
| 43 |
|
| 44 |
else:
|
| 45 |
groq_client = Groq(api_key=API_KEY)
|
| 46 |
-
logger.info("
|
| 47 |
-
|
| 48 |
-
|
| 49 |
|
| 50 |
# ---------------------------------------
|
| 51 |
# 입력/출력 모델
|
|
@@ -100,7 +97,6 @@ def parse_naver(soup: bs):
|
|
| 100 |
title_text = title.get_text(strip=True) if title else "제목 없음"
|
| 101 |
time_tag = soup.select_one("span.media_end_head_info_datestamp_time")
|
| 102 |
time_text = time_tag.get_text(strip=True) if time_tag else "시간 없음"
|
| 103 |
-
|
| 104 |
content_area = soup.find("div", {"id": "newsct_article"}) or soup.find("div", {"id": "dic_area"})
|
| 105 |
if content_area:
|
| 106 |
paragraphs = content_area.find_all("p")
|
|
@@ -365,11 +361,11 @@ def parse_news(req: NewsRequest):
|
|
| 365 |
# ---------------------------------------
|
| 366 |
krx_listings: pd.DataFrame = None
|
| 367 |
us_listings: pd.DataFrame = None
|
| 368 |
-
|
| 369 |
|
| 370 |
@app.on_event("startup")
|
| 371 |
async def load_initial_data():
|
| 372 |
-
global krx_listings, us_listings
|
| 373 |
logger.info("✅ 서버 시작: 초기 데이터 로딩을 시작합니다...")
|
| 374 |
try:
|
| 375 |
krx_listings = await run_in_threadpool(fdr.StockListing, 'KRX')
|
|
@@ -379,7 +375,6 @@ async def load_initial_data():
|
|
| 379 |
amex = await run_in_threadpool(fdr.StockListing, 'AMEX')
|
| 380 |
us_listings = pd.concat([nasdaq, nyse, amex], ignore_index=True)
|
| 381 |
logger.info("📊 미국 상장 기업 목록 로딩 완료.")
|
| 382 |
-
translator = Translator()
|
| 383 |
logger.info("🌐 번역기 초기화 완료.")
|
| 384 |
logger.info("✅ 초기 데이터 로딩 성공.")
|
| 385 |
except Exception as e:
|
|
@@ -445,4 +440,4 @@ async def get_stock_data_by_name(company_name: str = Query(..., description="조
|
|
| 445 |
# 실행
|
| 446 |
# ---------------------------------------
|
| 447 |
if __name__ == "__main__":
|
| 448 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
|
|
|
| 1 |
+
from pydoc import text
|
| 2 |
from fastapi import FastAPI, HTTPException, Query
|
| 3 |
import uvicorn
|
| 4 |
from pydantic import BaseModel
|
|
|
|
| 23 |
from fastapi.middleware.cors import CORSMiddleware
|
| 24 |
import traceback
|
| 25 |
from datetime import datetime, timedelta
|
|
|
|
| 26 |
from starlette.concurrency import run_in_threadpool
|
| 27 |
import FinanceDataReader as fdr
|
| 28 |
from groq import Groq
|
|
|
|
| 36 |
|
| 37 |
API_KEY = os.getenv("Groq_API_KEY")
|
| 38 |
|
|
|
|
| 39 |
if not API_KEY:
|
| 40 |
# API 키가 없으면 에러를 발생시키거나 경고
|
| 41 |
+
print(":x: Groq_API_KEY 환경 변수가 설정되지 않았습니다.")
|
| 42 |
|
| 43 |
else:
|
| 44 |
groq_client = Groq(api_key=API_KEY)
|
| 45 |
+
logger.info(":white_check_mark: Groq API 설정 완료 (환경 변수 사용)")
|
|
|
|
|
|
|
| 46 |
|
| 47 |
# ---------------------------------------
|
| 48 |
# 입력/출력 모델
|
|
|
|
| 97 |
title_text = title.get_text(strip=True) if title else "제목 없음"
|
| 98 |
time_tag = soup.select_one("span.media_end_head_info_datestamp_time")
|
| 99 |
time_text = time_tag.get_text(strip=True) if time_tag else "시간 없음"
|
|
|
|
| 100 |
content_area = soup.find("div", {"id": "newsct_article"}) or soup.find("div", {"id": "dic_area"})
|
| 101 |
if content_area:
|
| 102 |
paragraphs = content_area.find_all("p")
|
|
|
|
| 361 |
# ---------------------------------------
|
| 362 |
krx_listings: pd.DataFrame = None
|
| 363 |
us_listings: pd.DataFrame = None
|
| 364 |
+
|
| 365 |
|
| 366 |
@app.on_event("startup")
|
| 367 |
async def load_initial_data():
|
| 368 |
+
global krx_listings, us_listings
|
| 369 |
logger.info("✅ 서버 시작: 초기 데이터 로딩을 시작합니다...")
|
| 370 |
try:
|
| 371 |
krx_listings = await run_in_threadpool(fdr.StockListing, 'KRX')
|
|
|
|
| 375 |
amex = await run_in_threadpool(fdr.StockListing, 'AMEX')
|
| 376 |
us_listings = pd.concat([nasdaq, nyse, amex], ignore_index=True)
|
| 377 |
logger.info("📊 미국 상장 기업 목록 로딩 완료.")
|
|
|
|
| 378 |
logger.info("🌐 번역기 초기화 완료.")
|
| 379 |
logger.info("✅ 초기 데이터 로딩 성공.")
|
| 380 |
except Exception as e:
|
|
|
|
| 440 |
# 실행
|
| 441 |
# ---------------------------------------
|
| 442 |
if __name__ == "__main__":
|
| 443 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|