Leesn465 commited on
Commit
4623c5a
·
verified ·
1 Parent(s): 00c7c49

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +27 -19
main.py CHANGED
@@ -538,27 +538,35 @@ async def produce_progress(analysis_id: str, user_id: str | None, percent: int,
538
 
539
  def get_stock_info(company_name: str) -> Dict[str, str] | None:
540
  try:
541
- # 1. 한국 주식(KRX) 검색
542
- if krx_listings is not None:
543
- kr_match = krx_listings[krx_listings['Name'].str.contains(company_name, case=False, na=False)]
544
- if not kr_match.empty:
545
- s = kr_match.iloc[0]
546
- return {"market": "KRX", "symbol": s['Code'], "name": s['Name']}
547
-
548
- # 2. 미국 주식 검색 (번역기 없이 이름으로 직접 검색)
549
- if us_listings is not None:
550
- # 영어 이름이 포함되어 있을 수 있으므로 대소문자 무시하고 검색
551
- us_match = us_listings[
552
- us_listings['Name'].str.contains(company_name, case=False, na=False) |
553
- us_listings['Symbol'].str.fullmatch(company_name, case=False)
554
- ]
555
- if not us_match.empty:
556
- s = us_match.iloc[0]
557
- return {"market": "US", "symbol": s['Symbol'], "name": s['Name']}
 
 
 
 
 
 
 
 
558
 
559
  except Exception as e:
560
- logger.error(f"주식 종목 검색 중 오류 발생: {e}")
561
-
562
  return None
563
 
564
 
 
538
 
539
  def get_stock_info(company_name: str) -> Dict[str, str] | None:
540
  try:
541
+ name = (company_name or "").strip()
542
+ if not name:
543
+ return None
544
+
545
+ # 1) KRX
546
+ if krx_listings is not None and not krx_listings.empty:
547
+ # code 컬럼 자동 선택
548
+ code_col = 'Code' if 'Code' in krx_listings.columns else ('Symbol' if 'Symbol' in krx_listings.columns else None)
549
+ if code_col and 'Name' in krx_listings.columns:
550
+ kr_match = krx_listings[krx_listings['Name'].str.contains(name, case=False, na=False)]
551
+ if not kr_match.empty:
552
+ s = kr_match.iloc[0]
553
+ code = str(s[code_col]).zfill(6)
554
+ return {"market": "KRX", "symbol": code, "name": s['Name']}
555
+
556
+ # 2) US
557
+ if us_listings is not None and not us_listings.empty:
558
+ if 'Name' in us_listings.columns and 'Symbol' in us_listings.columns:
559
+ us_match = us_listings[
560
+ us_listings['Name'].str.contains(name, case=False, na=False) |
561
+ us_listings['Symbol'].str.fullmatch(name, case=False)
562
+ ]
563
+ if not us_match.empty:
564
+ s = us_match.iloc[0]
565
+ return {"market": "US", "symbol": str(s['Symbol']), "name": s['Name']}
566
 
567
  except Exception as e:
568
+ logger.error(f"주식 종목 검색 중 오류 발생: {repr(e)}", exc_info=True)
569
+
570
  return None
571
 
572