Skip to content

Commit 84373de

Browse files
committed
fix the bug that the HS STMBOLS URL is faild
1 parent 82f1ef2 commit 84373de

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

scripts/data_collector/utils.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pathlib import Path
1414
from typing import Iterable, Tuple, List
1515

16+
import akshare as ak
1617
import numpy as np
1718
import pandas as pd
1819
from loguru import logger
@@ -202,18 +203,9 @@ def _get_symbol():
202203
-------
203204
{600000.ss, 600001.ss, 600002.ss, 600003.ss, ...}
204205
"""
205-
url = "http://99.push2.eastmoney.com/api/qt/clist/get?pn=1&pz=10000&po=1&np=1&fs=m:0+t:6,m:0+t:80,m:1+t:2,m:1+t:23,m:0+t:81+s:2048&fields=f12"
206-
try:
207-
resp = requests.get(url, timeout=None)
208-
resp.raise_for_status()
209-
except requests.exceptions.HTTPError as e:
210-
raise requests.exceptions.HTTPError(f"Request to {url} failed with status code {resp.status_code}") from e
211-
212-
try:
213-
_symbols = [_v["f12"] for _v in resp.json()["data"]["diff"]]
214-
except Exception as e:
215-
logger.warning("An error occurred while extracting data from the response.")
216-
raise
206+
stock_info_a_code_name_df = ak.stock_info_a_code_name()
207+
stock_codes = stock_info_a_code_name_df['code'].tolist()
208+
_symbols = [code for code in stock_codes if code and code.strip()]
217209

218210
if len(_symbols) < 3900:
219211
raise ValueError("The complete list of stocks is not available.")

0 commit comments

Comments
 (0)