@@ -252,6 +252,10 @@ def _cache_key(symbol: str, date_str: str, source: str) -> str:
252252
253253
254254def _cache_path (symbol : str , date_str : str , source : str ) -> Path :
255+ return CACHE_DIR / date_str / _cache_key (symbol , date_str , source )
256+
257+
258+ def _cache_write_path (symbol : str , date_str : str , source : str ) -> Path :
255259 d = CACHE_DIR / date_str
256260 d .mkdir (parents = True , exist_ok = True )
257261 return d / _cache_key (symbol , date_str , source )
@@ -280,7 +284,7 @@ def cache_save(symbol: str, date_str: str, source: str, data: dict[str, Any]) ->
280284 payload = data .get ("data" ) if isinstance (data , dict ) else None
281285 if payload is not None and not payload : # data: [] / data: {}
282286 return
283- p = _cache_path (symbol , date_str , source )
287+ p = _cache_write_path (symbol , date_str , source )
284288 try :
285289 with open (p , "w" , encoding = "utf-8" ) as f :
286290 json .dump (data , f , ensure_ascii = False , default = str )
@@ -1603,13 +1607,17 @@ def normalize_stock_symbol(symbol: str) -> tuple[str, str]:
16031607def get_index (date_str : str ) -> list [dict [str , Any ]]:
16041608 cached = cache_load ("index_all" , date_str , "eastmoney" )
16051609 if cached :
1606- return cached .get ("data" , [])
1610+ cached_rows = cached .get ("data" )
1611+ if isinstance (cached_rows , list ):
1612+ return cached_rows
1613+ diag ("Ignored cached A-share index because data is not a list" )
16071614
16081615 url = INDEX_URL .format (secids = INDEX_SECIDS , fields = INDEX_FIELDS , ts = datetime .now ().timestamp ())
16091616 data = fetch_json (url , {"Referer" : "https://quote.eastmoney.com/" })
16101617 if "_error" in data :
16111618 diag (f"Eastmoney index: { data ['_error' ]} " )
1612- result = data .get ("data" , {}).get ("diff" , []) if "_error" not in data else []
1619+ diff = data .get ("data" , {}).get ("diff" , []) if "_error" not in data else []
1620+ result = diff if isinstance (diff , list ) else []
16131621 # 东财失败时降级到新浪
16141622 if not result :
16151623 result = _fetch_a_indices_sina ()
0 commit comments