akshare 1.16.55__py3-none-any.whl → 1.16.56__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- akshare/__init__.py +2 -1
- akshare/stock/stock_zh_a_sina.py +24 -17
- akshare/utils/multi_decrypt.py +43 -0
- {akshare-1.16.55.dist-info → akshare-1.16.56.dist-info}/METADATA +1 -1
- {akshare-1.16.55.dist-info → akshare-1.16.56.dist-info}/RECORD +8 -7
- {akshare-1.16.55.dist-info → akshare-1.16.56.dist-info}/WHEEL +0 -0
- {akshare-1.16.55.dist-info → akshare-1.16.56.dist-info}/licenses/LICENSE +0 -0
- {akshare-1.16.55.dist-info → akshare-1.16.56.dist-info}/top_level.txt +0 -0
akshare/__init__.py
CHANGED
@@ -3064,9 +3064,10 @@ amac_manager_cancelled_info # 中国证券投资基金业协会-信息公示-诚
|
|
3064
3064
|
1.16.53 fix: fix stock_yjbb_em interface
|
3065
3065
|
1.16.54 fix: fix stock_zh_a_spot_em interface
|
3066
3066
|
1.16.55 fix: fix stock_zh_a_spot_em interface
|
3067
|
+
1.16.56 fix: fix stock_zh_a_daily interface
|
3067
3068
|
"""
|
3068
3069
|
|
3069
|
-
__version__ = "1.16.
|
3070
|
+
__version__ = "1.16.56"
|
3070
3071
|
__author__ = "AKFamily"
|
3071
3072
|
|
3072
3073
|
import sys
|
akshare/stock/stock_zh_a_sina.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env python
|
2
2
|
# -*- coding:utf-8 -*-
|
3
3
|
"""
|
4
|
-
Date:
|
4
|
+
Date: 2025/3/20 19:00
|
5
5
|
Desc: 新浪财经-A股-实时行情数据和历史行情数据(包含前复权和后复权因子)
|
6
6
|
https://finance.sina.com.cn/realstock/company/sh689009/nc.shtml
|
7
7
|
"""
|
@@ -11,8 +11,6 @@ import re
|
|
11
11
|
|
12
12
|
import pandas as pd
|
13
13
|
import requests
|
14
|
-
import py_mini_racer
|
15
|
-
from tqdm import tqdm
|
16
14
|
|
17
15
|
from akshare.stock.cons import (
|
18
16
|
zh_sina_a_stock_payload,
|
@@ -25,6 +23,8 @@ from akshare.stock.cons import (
|
|
25
23
|
zh_sina_a_stock_amount_url,
|
26
24
|
)
|
27
25
|
from akshare.utils import demjson
|
26
|
+
from akshare.utils.multi_decrypt import execute_js_in_executor
|
27
|
+
from akshare.utils.tqdm import get_tqdm
|
28
28
|
|
29
29
|
|
30
30
|
def _get_zh_a_page_count() -> int:
|
@@ -52,13 +52,14 @@ def stock_zh_a_spot() -> pd.DataFrame:
|
|
52
52
|
big_df = pd.DataFrame()
|
53
53
|
page_count = _get_zh_a_page_count()
|
54
54
|
zh_sina_stock_payload_copy = zh_sina_a_stock_payload.copy()
|
55
|
+
tqdm = get_tqdm()
|
55
56
|
for page in tqdm(
|
56
57
|
range(1, page_count + 1), leave=False, desc="Please wait for a moment"
|
57
58
|
):
|
58
59
|
zh_sina_stock_payload_copy.update({"page": page})
|
59
60
|
r = requests.get(zh_sina_a_stock_url, params=zh_sina_stock_payload_copy)
|
60
61
|
data_json = demjson.decode(r.text)
|
61
|
-
big_df = pd.concat([big_df, pd.DataFrame(data_json)], ignore_index=True)
|
62
|
+
big_df = pd.concat(objs=[big_df, pd.DataFrame(data_json)], ignore_index=True)
|
62
63
|
|
63
64
|
big_df = big_df.astype(
|
64
65
|
{
|
@@ -174,13 +175,15 @@ def stock_zh_a_daily(
|
|
174
175
|
return _fq_factor(adjust.split("-")[0])
|
175
176
|
|
176
177
|
r = requests.get(zh_sina_a_stock_hist_url.format(symbol))
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
"
|
181
|
-
|
178
|
+
# 使用示例
|
179
|
+
dict_list = execute_js_in_executor(
|
180
|
+
hk_js_decode, # JS 代码
|
181
|
+
"call", # 方法类型
|
182
|
+
"d", # 函数名
|
183
|
+
r.text.split("=")[1].split(";")[0].replace('"', ""), # 函数参数
|
184
|
+
)
|
182
185
|
data_df = pd.DataFrame(dict_list)
|
183
|
-
data_df.index = pd.to_datetime(data_df["date"]).dt.date
|
186
|
+
data_df.index = pd.to_datetime(data_df["date"], errors="coerce").dt.date
|
184
187
|
del data_df["date"]
|
185
188
|
try:
|
186
189
|
del data_df["prevclose"]
|
@@ -343,12 +346,13 @@ def stock_zh_a_cdr_daily(
|
|
343
346
|
:return: specific data
|
344
347
|
:rtype: pandas.DataFrame
|
345
348
|
"""
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
"d",
|
351
|
-
|
349
|
+
r = requests.get(zh_sina_a_stock_hist_url.format(symbol))
|
350
|
+
dict_list = execute_js_in_executor(
|
351
|
+
hk_js_decode, # JS 代码
|
352
|
+
"call", # 方法类型
|
353
|
+
"d", # 函数名
|
354
|
+
r.text.split("=")[1].split(";")[0].replace('"', ""), # 函数参数
|
355
|
+
)
|
352
356
|
data_df = pd.DataFrame(dict_list)
|
353
357
|
data_df.index = pd.to_datetime(data_df["date"])
|
354
358
|
del data_df["date"]
|
@@ -393,7 +397,10 @@ def stock_zh_a_minute(
|
|
393
397
|
data_json = json.loads(data_text.split("=(")[1].split(");")[0])
|
394
398
|
temp_df = pd.DataFrame(data_json).iloc[:, :6]
|
395
399
|
except: # noqa: E722
|
396
|
-
url =
|
400
|
+
url = (
|
401
|
+
f"https://quotes.sina.cn/cn/api/jsonp_v2.php/var%20_{symbol}_{period}_1658852984203="
|
402
|
+
f"/CN_MarketDataService.getKLineData"
|
403
|
+
)
|
397
404
|
params = {
|
398
405
|
"symbol": symbol,
|
399
406
|
"scale": period,
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import concurrent.futures
|
2
|
+
|
3
|
+
|
4
|
+
# 定义在模块级别的函数
|
5
|
+
def js_executor_function(js_code_str, method, args):
|
6
|
+
"""在新进程中执行 JavaScript 代码的函数"""
|
7
|
+
from py_mini_racer import MiniRacer
|
8
|
+
|
9
|
+
js_code = MiniRacer()
|
10
|
+
js_code.eval(js_code_str)
|
11
|
+
|
12
|
+
if method == "call":
|
13
|
+
fn_name = args[0]
|
14
|
+
fn_args = args[1:]
|
15
|
+
return js_code.call(fn_name, *fn_args)
|
16
|
+
elif method == "eval":
|
17
|
+
return js_code.eval(args[0])
|
18
|
+
else:
|
19
|
+
raise ValueError(f"不支持的方法: {method}")
|
20
|
+
|
21
|
+
|
22
|
+
def execute_js_in_executor(js_code_str, method, *args, timeout=30):
|
23
|
+
"""
|
24
|
+
使用 ProcessPoolExecutor 在独立进程中执行 JavaScript
|
25
|
+
|
26
|
+
参数:
|
27
|
+
js_code_str: JavaScript 代码字符串
|
28
|
+
method: 'call' 或 'eval'
|
29
|
+
args: 如果 method 是 'call',第一个参数是函数名,后续是函数参数
|
30
|
+
如果 method 是 'eval',只需提供一个参数:要评估的代码
|
31
|
+
timeout: 超时时间(秒)
|
32
|
+
|
33
|
+
返回:
|
34
|
+
执行结果
|
35
|
+
"""
|
36
|
+
with concurrent.futures.ProcessPoolExecutor(max_workers=1) as executor:
|
37
|
+
future = executor.submit(js_executor_function, js_code_str, method, args)
|
38
|
+
try:
|
39
|
+
return future.result(timeout=timeout)
|
40
|
+
except concurrent.futures.TimeoutError:
|
41
|
+
# 清理资源并抛出超时异常
|
42
|
+
executor.shutdown(wait=False)
|
43
|
+
raise TimeoutError("JavaScript 执行超时")
|
@@ -1,4 +1,4 @@
|
|
1
|
-
akshare/__init__.py,sha256=
|
1
|
+
akshare/__init__.py,sha256=VZRRasA85-MmK5vJsXEZ8v5ETXeFwdbiyFS2MIj655w,191719
|
2
2
|
akshare/datasets.py,sha256=rKuRNZrqi6IMsZ9nyvO3Rx02js0tH3zMLjz8HQNAoPQ,963
|
3
3
|
akshare/exceptions.py,sha256=WEJjIhSmJ_xXNW6grwV4nufE_cfmmyuhmueVGiN1VAg,878
|
4
4
|
akshare/request.py,sha256=HtFFf9MhfEibR-ETWe-1Tts6ELU4VKSqA-ghaXjegQM,4252
|
@@ -281,7 +281,7 @@ akshare/stock/stock_us_pink.py,sha256=BX7-tG4Zs0k2vSYGxHH0Yob-moD6AAu2a-ytZpxgIR
|
|
281
281
|
akshare/stock/stock_us_sina.py,sha256=D4fhJgpmvnlVoeSV2wQQ7H6lig8h6vaJp71o88dZhDg,8200
|
282
282
|
akshare/stock/stock_weibo_nlp.py,sha256=eM7ofsNSrKiYeS0g38Qj9CxT6dkJZrn_pmziIiTqp4U,3286
|
283
283
|
akshare/stock/stock_xq.py,sha256=mPBVg2zA4XkTVAUXeZx8c3nzchm4D1AaMBbC-g87yLQ,4641
|
284
|
-
akshare/stock/stock_zh_a_sina.py,sha256=
|
284
|
+
akshare/stock/stock_zh_a_sina.py,sha256=VrtDVSp_7S82H2RB8CD7CkDt8tBZeLhVUfRteWkva-4,19061
|
285
285
|
akshare/stock/stock_zh_a_special.py,sha256=VInvKbA6u_hJjjUKj7I5pG9rqt3kSZzJrZNfVs2Fqas,10169
|
286
286
|
akshare/stock/stock_zh_a_tick_tx.py,sha256=TJUAWLKAeoLEaVVJQlj0t-1smZGoAO0X0rPsUPVhZZ4,2131
|
287
287
|
akshare/stock/stock_zh_ah_tx.py,sha256=1DfvP1xF9G4jDnqlacZiYIMWZBujxW9Kycre3yr6MhM,9212
|
@@ -387,12 +387,13 @@ akshare/utils/cons.py,sha256=PFZndkG3lMW1Qhg-wqcZmSowFXwQUsYYCLZT4s1Xkwc,225
|
|
387
387
|
akshare/utils/context.py,sha256=Hl4kPUzQ1CecRzu5JvTKpTpiMLfzAzYzG7F5hktlsCQ,934
|
388
388
|
akshare/utils/demjson.py,sha256=xW2z0UGS2zzyH_dzhd765ZveuXRbfjkM7KBiI8H5fJA,241609
|
389
389
|
akshare/utils/func.py,sha256=4cwmXFztU86yJNONJ40KJLvsIEQHBbct4iMm3zT2v30,2315
|
390
|
+
akshare/utils/multi_decrypt.py,sha256=0GDWfnMTd71ncLR_YqmgAcP6vfOLRBNI_O8M1OeJUmI,1446
|
390
391
|
akshare/utils/token_process.py,sha256=K4rGXjh_tgugbRcyOK2h2x0jP3PT65IIK7nxhUKhOeQ,666
|
391
392
|
akshare/utils/tqdm.py,sha256=MuPNwcswkOGjwWQOMWXi9ZvQ_RmW4obCWRj2i7HM7FE,847
|
392
|
-
akshare-1.16.
|
393
|
+
akshare-1.16.56.dist-info/licenses/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
|
393
394
|
tests/__init__.py,sha256=gNzhlO0UPjFq6Ieb38kaVIODXv4cTDByrdohAZnDYt4,82
|
394
395
|
tests/test_func.py,sha256=j1MGYbZI2if2j_LY1S4FLsf4qfq4NwVqD5wmRlv5Log,832
|
395
|
-
akshare-1.16.
|
396
|
-
akshare-1.16.
|
397
|
-
akshare-1.16.
|
398
|
-
akshare-1.16.
|
396
|
+
akshare-1.16.56.dist-info/METADATA,sha256=eIzWK2w5LkEbj2Vt8n9UUA_xG0xQAoTLZZIcjh6EMk0,13767
|
397
|
+
akshare-1.16.56.dist-info/WHEEL,sha256=tTnHoFhvKQHCh4jz3yCn0WPTYIy7wXx3CJtJ7SJGV7c,91
|
398
|
+
akshare-1.16.56.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
|
399
|
+
akshare-1.16.56.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|