From 21a8173963175454aea042443e16923d4d4196d5 Mon Sep 17 00:00:00 2001 From: gahusb Date: Wed, 28 Jan 2026 00:55:47 +0900 Subject: [PATCH] =?UTF-8?q?=EC=A3=BC=EC=9A=94=EC=A7=80=EC=88=98=20?= =?UTF-8?q?=ED=95=B4=EC=99=B8=20=EC=98=A4=EB=A5=98=20=EC=88=98=EC=A0=95=20?= =?UTF-8?q?=EB=B0=8F=20=EC=9B=90=EB=8B=AC=EB=9F=AC=ED=99=98=EC=9C=A8=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- stock-lab/app/scraper.py | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/stock-lab/app/scraper.py b/stock-lab/app/scraper.py index b933052..f2aa605 100644 --- a/stock-lab/app/scraper.py +++ b/stock-lab/app/scraper.py @@ -186,9 +186,9 @@ def fetch_major_indices() -> Dict[str, Any]: soup_world = BeautifulSoup(resp_world.content, "html.parser", from_encoding="cp949") world_targets = [ - {"key": "DJI", "sym": "DJI@DJI"}, - {"key": "NAS", "sym": "NAS@IXIC"}, - {"key": "SPI", "sym": "SPI@SPX"}, + {"key": "DJI", "name": "다우산업", "sym": "DJI@DJI"}, + {"key": "NAS", "name": "나스닥", "sym": "NAS@IXIC"}, + {"key": "SPI", "name": "S&P500", "sym": "SPI@SPX"}, ] for wt in world_targets: @@ -228,7 +228,7 @@ def fetch_major_indices() -> Dict[str, Any]: direction = "blue" indices.append({ - "name": wt["key"], + "name": wt["name"], # 한글 이름 사용 "value": value, "change_value": change_val, "change_percent": change_pct, @@ -238,6 +238,38 @@ def fetch_major_indices() -> Dict[str, Any]: except Exception as e: print(f"[StockLab] World indices failed: {e}") + + # --- 환율 (USD/KRW) --- + try: + resp_ex = requests.get("https://finance.naver.com/marketindex/", headers=headers, timeout=5) + soup_ex = BeautifulSoup(resp_ex.content, "html.parser", from_encoding="cp949") + + usd_item = soup_ex.select_one("#exchangeList li.on > a.head.usd") + if usd_item: + value = usd_item.select_one(".value").get_text(strip=True) + change_val = usd_item.select_one(".change").get_text(strip=True) + + # 방향 (blind 텍스트: 상승, 하락) + direction = "" + blind_txt = usd_item.select_one(".blind").get_text(strip=True) + if "상승" in blind_txt: direction = "red" + elif "하락" in blind_txt: direction = "blue" + + # 등락률은 리스트에는 안나오고 상세에 나오지만, 여기선 생략하거나 계산 가능. + # 일단 UI 통일성을 위해 빈값 혹은 계산된 값 등 처리. + # 네이버 메인 환율 영역엔 등락률이 텍스트로 바로 안보임 (title 속성 등에 있을수 있음). + # 여기서는 간단히 값만 처리. + + indices.append({ + "name": "원달러 환율", + "value": value, + "change_value": change_val, + "change_percent": "", # 메인 리스트에서 바로 안보임 + "direction": direction, + "type": "exchange" + }) + except Exception as e: + print(f"[StockLab] Exchange rate failed: {e}") return {"indices": indices, "crawled_at": time.strftime("%Y-%m-%d %H:%M:%S")}