주식 해외 지수 응답 추가

This commit is contained in:
2026-01-28 00:44:09 +09:00
parent 55863d7744
commit f6fcff0faf

View File

@@ -186,33 +186,52 @@ def fetch_major_indices() -> Dict[str, Any]:
soup_world = BeautifulSoup(resp_world.content, "html.parser", from_encoding="cp949")
world_targets = [
{"key": "DJI", "selector": ".sise_major .data_list li:nth-child(1)"},
{"key": "NAS", "selector": ".sise_major .data_list li:nth-child(2)"},
{"key": "SPI", "selector": ".sise_major .data_list li:nth-child(3)"},
{"key": "DJI", "sym": "DJI@DJI"},
{"key": "NAS", "sym": "NAS@IXIC"},
{"key": "SPI", "sym": "SPI@SPX"},
]
for wt in world_targets:
li = soup_world.select_one(wt["selector"])
if not li: continue
# 심볼 링크로 찾기 (가장 정확함)
a_tag = soup_world.select_one(f"a[href*='symbol={wt['sym']}']")
if not a_tag:
continue
# 값: dd.point_status strong
val_tag = li.select_one("dd.point_status strong")
# 상위 dl 태그 찾기
dl = a_tag.find_parent("dl")
if not dl:
continue
# 값 파싱 (dd.point_status)
status_dd = dl.select_one("dd.point_status")
if not status_dd:
continue
# 1. 현재가 (strong)
val_tag = status_dd.select_one("strong")
value = val_tag.get_text(strip=True) if val_tag else ""
# 등락: dd.point_status em
# 2. 등락폭 (em)
change_val_tag = status_dd.select_one("em")
change_val = change_val_tag.get_text(strip=True) if change_val_tag else ""
# 3. 등락률 (span)
change_pct_tag = status_dd.select_one("span")
change_pct = change_pct_tag.get_text(strip=True) if change_pct_tag else ""
# 4. 방향 (dl 클래스 활용)
direction = ""
status_dd = li.select_one("dd.point_status")
if status_dd:
em = status_dd.select_one("em")
if em:
if "red" in em.get("class", []): direction = "red"
elif "blue" in em.get("class", []): direction = "blue"
dl_classes = dl.get("class", [])
if "point_up" in dl_classes:
direction = "red"
elif "point_dn" in dl_classes:
direction = "blue"
indices.append({
"name": wt["key"],
"value": value,
"change_value": "",
"change_percent": "",
"change_value": change_val,
"change_percent": change_pct,
"direction": direction,
"type": "overseas"
})