주식 해외 지수 응답 추가
This commit is contained in:
@@ -186,33 +186,52 @@ def fetch_major_indices() -> Dict[str, Any]:
|
|||||||
soup_world = BeautifulSoup(resp_world.content, "html.parser", from_encoding="cp949")
|
soup_world = BeautifulSoup(resp_world.content, "html.parser", from_encoding="cp949")
|
||||||
|
|
||||||
world_targets = [
|
world_targets = [
|
||||||
{"key": "DJI", "selector": ".sise_major .data_list li:nth-child(1)"},
|
{"key": "DJI", "sym": "DJI@DJI"},
|
||||||
{"key": "NAS", "selector": ".sise_major .data_list li:nth-child(2)"},
|
{"key": "NAS", "sym": "NAS@IXIC"},
|
||||||
{"key": "SPI", "selector": ".sise_major .data_list li:nth-child(3)"},
|
{"key": "SPI", "sym": "SPI@SPX"},
|
||||||
]
|
]
|
||||||
|
|
||||||
for wt in world_targets:
|
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
|
# 상위 dl 태그 찾기
|
||||||
val_tag = li.select_one("dd.point_status strong")
|
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 ""
|
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 = ""
|
direction = ""
|
||||||
status_dd = li.select_one("dd.point_status")
|
dl_classes = dl.get("class", [])
|
||||||
if status_dd:
|
if "point_up" in dl_classes:
|
||||||
em = status_dd.select_one("em")
|
direction = "red"
|
||||||
if em:
|
elif "point_dn" in dl_classes:
|
||||||
if "red" in em.get("class", []): direction = "red"
|
direction = "blue"
|
||||||
elif "blue" in em.get("class", []): direction = "blue"
|
|
||||||
|
|
||||||
indices.append({
|
indices.append({
|
||||||
"name": wt["key"],
|
"name": wt["key"],
|
||||||
"value": value,
|
"value": value,
|
||||||
"change_value": "",
|
"change_value": change_val,
|
||||||
"change_percent": "",
|
"change_percent": change_pct,
|
||||||
"direction": direction,
|
"direction": direction,
|
||||||
"type": "overseas"
|
"type": "overseas"
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user