akshare 1.16.55__py3-none-any.whl → 1.16.57__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 CHANGED
@@ -3064,9 +3064,11 @@ 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
3068
+ 1.16.57 fix: fix stock_market_pe_lg interface
3067
3069
  """
3068
3070
 
3069
- __version__ = "1.16.55"
3071
+ __version__ = "1.16.57"
3070
3072
  __author__ = "AKFamily"
3071
3073
 
3072
3074
  import sys
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2023/12/5 19:20
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
- js_code = py_mini_racer.MiniRacer()
178
- js_code.eval(hk_js_decode)
179
- dict_list = js_code.call(
180
- "d", r.text.split("=")[1].split(";")[0].replace('"', "")
181
- ) # 执行js解密代码
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
- res = requests.get(zh_sina_a_stock_hist_url.format(symbol))
347
- js_code = py_mini_racer.MiniRacer()
348
- js_code.eval(hk_js_decode)
349
- dict_list = js_code.call(
350
- "d", res.text.split("=")[1].split(";")[0].replace('"', "")
351
- ) # 执行js解密代码
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 = f"https://quotes.sina.cn/cn/api/jsonp_v2.php/var%20_{symbol}_{period}_1658852984203=/CN_MarketDataService.getKLineData"
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,
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env python
2
2
  # -*- coding:utf-8 -*-
3
3
  """
4
- Date: 2024/10/19 21:30
4
+ Date: 2025/3/20 20:00
5
5
  Desc: 乐咕乐股-A 股市盈率和市净率
6
6
  https://legulegu.com/stockdata/shanghaiPE
7
7
  """
@@ -317,9 +317,6 @@ function E(n, e, t, r, o, f, i) {
317
317
  return A(t ^ (e | ~r), n, e, o, f, i)
318
318
  }
319
319
  """
320
- js_functions = py_mini_racer.MiniRacer()
321
- js_functions.eval(hash_code)
322
- token = js_functions.call("hex", datetime.now().date().isoformat()).lower()
323
320
 
324
321
 
325
322
  def stock_market_pe_lg(symbol: str = "深证") -> pd.DataFrame:
@@ -331,6 +328,9 @@ def stock_market_pe_lg(symbol: str = "深证") -> pd.DataFrame:
331
328
  :return: 指定市场的市盈率数据
332
329
  :rtype: pandas.DataFrame
333
330
  """
331
+ js_functions = py_mini_racer.MiniRacer()
332
+ js_functions.eval(hash_code)
333
+ token = js_functions.call("hex", datetime.now().date().isoformat()).lower()
334
334
  if symbol in {"上证", "深证", "创业板"}:
335
335
  url = "https://legulegu.com/api/stock-data/market-pe"
336
336
  symbol_map = {
@@ -404,6 +404,9 @@ def stock_index_pe_lg(symbol: str = "沪深300") -> pd.DataFrame:
404
404
  :return: 指定指数的市盈率数据
405
405
  :rtype: pandas.DataFrame
406
406
  """
407
+ js_functions = py_mini_racer.MiniRacer()
408
+ js_functions.eval(hash_code)
409
+ token = js_functions.call("hex", datetime.now().date().isoformat()).lower()
407
410
  symbol_map = {
408
411
  "上证50": "000016.SH",
409
412
  "沪深300": "000300.SH",
@@ -466,6 +469,9 @@ def stock_market_pb_lg(symbol: str = "上证") -> pd.DataFrame:
466
469
  :return: 指定市场的市净率数据
467
470
  :rtype: pandas.DataFrame
468
471
  """
472
+ js_functions = py_mini_racer.MiniRacer()
473
+ js_functions.eval(hash_code)
474
+ token = js_functions.call("hex", datetime.now().date().isoformat()).lower()
469
475
  url = "https://legulegu.com/api/stockdata/index-basic-pb"
470
476
  symbol_map = {"上证": "1", "深证": "2", "创业板": "4", "科创版": "7"}
471
477
  url_map = {
@@ -511,6 +517,9 @@ def stock_index_pb_lg(symbol: str = "上证50") -> pd.DataFrame:
511
517
  :return: 指定指数的市净率数据
512
518
  :rtype: pandas.DataFrame
513
519
  """
520
+ js_functions = py_mini_racer.MiniRacer()
521
+ js_functions.eval(hash_code)
522
+ token = js_functions.call("hex", datetime.now().date().isoformat()).lower()
514
523
  symbol_map = {
515
524
  "上证50": "000016.SH",
516
525
  "沪深300": "000300.SH",
@@ -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,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: akshare
3
- Version: 1.16.55
3
+ Version: 1.16.57
4
4
  Summary: AKShare is an elegant and simple financial data interface library for Python, built for human beings!
5
5
  Home-page: https://github.com/akfamily/akshare
6
6
  Author: AKFamily
@@ -1,4 +1,4 @@
1
- akshare/__init__.py,sha256=sNChgkHXIPcKriuS95yWSsmW7KFlONxNXo3MLqud6-Y,191675
1
+ akshare/__init__.py,sha256=jzkG2puExLIua-1Q6qPR2FjRBi7wDNbs1PJd4PIH3NM,191765
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=ZobGnFMIR67ENk05ocqIkeiItLlgK67dW8ZjLdDss3s,18862
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
@@ -295,7 +295,7 @@ akshare/stock_feature/cons.py,sha256=UgwXlae3UpVRuhTt33nP-jmhNyug2mZLzuMgLja6pbA
295
295
  akshare/stock_feature/stock_a_below_net_asset_statistics.py,sha256=XrhZI-wLuXXufI5Nh1l9gUx9x7f0iDtdtKa14wexo54,2653
296
296
  akshare/stock_feature/stock_a_high_low.py,sha256=xS7btdwjlMvxrOu0I3qhezOqLV0gUuHl66FLB_ioxTo,2044
297
297
  akshare/stock_feature/stock_a_indicator.py,sha256=jOb9EVtPgcDPVziy_ZAo0RqHL3eoviwycbvp9Sr5wQw,4818
298
- akshare/stock_feature/stock_a_pe_and_pb.py,sha256=wf6AuJOCKwfYxskbrLjIjz21a1MzYvpjiCM6dSWfpfo,18604
298
+ akshare/stock_feature/stock_a_pe_and_pb.py,sha256=9HfjTSL_DTlAVvv7o3--pOdZiFwhRzYki7O5DfTrNW8,19089
299
299
  akshare/stock_feature/stock_account_em.py,sha256=PA-531xnv5uerFrYGc40mk8q8O0DGciHC_XVlE9udis,3342
300
300
  akshare/stock_feature/stock_all_pb.py,sha256=2yQLq03qXNbTB5AtJ-Q8uJldOluElH5zTjYneY3aaZ0,1194
301
301
  akshare/stock_feature/stock_analyst_em.py,sha256=Md3_G-Px0O1lk4dx5dCEKl8Vjgwt79Sh-FSh_sW1Elo,9508
@@ -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.55.dist-info/licenses/LICENSE,sha256=mmSZCPgfHiVw34LXuFArd-SUgQtBJ_QsIlh-kWlDHfs,1073
393
+ akshare-1.16.57.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.55.dist-info/METADATA,sha256=xiYUO8A4mokQW0CrUEx2pYlEJYF4AthRzBxlnzaZKko,13767
396
- akshare-1.16.55.dist-info/WHEEL,sha256=tTnHoFhvKQHCh4jz3yCn0WPTYIy7wXx3CJtJ7SJGV7c,91
397
- akshare-1.16.55.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
398
- akshare-1.16.55.dist-info/RECORD,,
396
+ akshare-1.16.57.dist-info/METADATA,sha256=vyKla8HWa_fe6sj2EYRCkAiKkGV4gMQroJOUJTMcQ9I,13767
397
+ akshare-1.16.57.dist-info/WHEEL,sha256=tTnHoFhvKQHCh4jz3yCn0WPTYIy7wXx3CJtJ7SJGV7c,91
398
+ akshare-1.16.57.dist-info/top_level.txt,sha256=jsf9ZzZPmHaISTVumQPsAw7vv7Yv-PdEVW70SMEelQQ,14
399
+ akshare-1.16.57.dist-info/RECORD,,