From 7fa5afac62d94124d37c2bb36418c04b8d74d37a Mon Sep 17 00:00:00 2001 From: Albert King Date: Fri, 1 Mar 2024 23:43:59 +0800 Subject: [PATCH] Date (#4560) * update date * add version 1.12.79 * fix futures_main_sina --- akshare/__init__.py | 3 ++- akshare/futures_derivative/futures_index_sina.py | 9 +++++---- docs/changelog.md | 6 ++++++ 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/akshare/__init__.py b/akshare/__init__.py index ce8b7821820..749c632d8bc 100644 --- a/akshare/__init__.py +++ b/akshare/__init__.py @@ -2691,9 +2691,10 @@ 1.12.76 fix: fix bond_zh_hs_spot interface 1.12.77 fix: fix futures_contract_info_shfe interface 1.12.78 fix: fix stock_info_sh_delist interface +1.12.79 fix: fix futures_main_sina interface """ -__version__ = "1.12.78" +__version__ = "1.12.79" __author__ = "AKFamily" import sys diff --git a/akshare/futures_derivative/futures_index_sina.py b/akshare/futures_derivative/futures_index_sina.py index 5cea018b8b3..7a80ee78230 100644 --- a/akshare/futures_derivative/futures_index_sina.py +++ b/akshare/futures_derivative/futures_index_sina.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding:utf-8 -*- """ -Date: 2023/11/5 20:00 +Date: 2024/3/1 23:00 Desc: 新浪财经-期货的主力合约数据 https://finance.sina.com.cn/futuremarket/index.shtml """ @@ -29,7 +29,8 @@ def zh_subscribe_exchange_symbol(symbol: str = "dce") -> pd.DataFrame: """ r = requests.get(zh_subscribe_exchange_symbol_url) r.encoding = "gb2312" - data_json = demjson.decode(r.text[r.text.find("{"): r.text.find("};") + 1]) + data_text = r.text + data_json = demjson.decode(data_text[data_text.find("{"): data_text.find("};") + 1]) if symbol == "czce": data_json["czce"].remove("郑州商品交易所") return pd.DataFrame(data_json["czce"]) @@ -121,7 +122,7 @@ def futures_main_sina( data_json = data_text[data_text.find("([") + 1: data_text.rfind("])") + 1] temp_df = pd.read_json(StringIO(data_json)) temp_df.columns = ["日期", "开盘价", "最高价", "最低价", "收盘价", "成交量", "持仓量", "动态结算价"] - temp_df["日期"] = pd.to_datetime(temp_df["日期"]).dt.date + temp_df["日期"] = pd.to_datetime(temp_df["日期"], errors="coerce").dt.date temp_df.set_index(keys=["日期"], inplace=True) temp_df.index = pd.to_datetime(temp_df.index) temp_df = temp_df[start_date:end_date] @@ -142,6 +143,6 @@ def futures_main_sina( print(futures_display_main_sina_df) futures_main_sina_hist = futures_main_sina( - symbol="CF0", start_date="20240124", end_date="20240131" + symbol="CF0", start_date="20240124", end_date="20240301" ) print(futures_main_sina_hist) diff --git a/docs/changelog.md b/docs/changelog.md index 8b525696f8b..790973a05f8 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -71,6 +71,10 @@ ## 更新说明详情 +1.12.79 fix: fix futures_main_sina interface + + 1. 修复 futures_main_sina 接口 + 1.12.78 fix: fix stock_info_sh_delist interface 1. 修复 stock_info_sh_delist 接口 @@ -3640,6 +3644,8 @@ ## 版本更新说明 +1.12.79 fix: fix futures_main_sina interface + 1.12.78 fix: fix stock_info_sh_delist interface 1.12.77 fix: fix futures_contract_info_shfe interface