ezKit 1.8.1__py3-none-any.whl → 1.8.2__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.
ezKit/cls.py ADDED
@@ -0,0 +1,90 @@
1
+ """财联社数据"""
2
+ import re
3
+
4
+ import pandas as pd
5
+ import requests
6
+ from loguru import logger
7
+
8
+ from . import stock, utils
9
+
10
+
11
+ def up_down_analysis(
12
+ target: str = "up_pool",
13
+ df: bool = False
14
+ ) -> list | pd.DataFrame | None:
15
+ """涨停跌停数据"""
16
+
17
+ if not utils.v_true(target, str):
18
+ logger.error(f"error type: {target}")
19
+ return None
20
+
21
+ info: str = "获取涨停池股票"
22
+ match True:
23
+ case True if target == "up_pool":
24
+ info = "获取涨停池股票"
25
+ case True if target == "continuous_up_pool":
26
+ info = "获取连板池股票"
27
+ case True if target == "up_open_pool":
28
+ info = "获取炸板池股票"
29
+ case True if target == "down_pool":
30
+ info = "获取跌停池股票"
31
+ case _:
32
+ pass
33
+
34
+ try:
35
+ logger.info(f"{info} ......")
36
+
37
+ user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
38
+ headers = {"User-Agent": user_agent}
39
+
40
+ # 涨停池: https://x-quote.cls.cn/quote/index/up_down_analysis?rever=1&way=last_px&type=up_pool
41
+ # 连板池: https://x-quote.cls.cn/quote/index/up_down_analysis?rever=1&way=last_px&type=continuous_up_pool
42
+ # 炸板池: https://x-quote.cls.cn/quote/index/up_down_analysis?rever=1&way=last_px&type=up_open_pool
43
+ # 跌停池: https://x-quote.cls.cn/quote/index/up_down_analysis?rever=1&way=last_px&type=down_pool
44
+ api = f"https://x-quote.cls.cn/quote/index/up_down_analysis?rever=1&way=last_px&type={target}"
45
+
46
+ response = requests.get(api, headers=headers, timeout=10)
47
+
48
+ response_dict: dict = response.json()
49
+
50
+ result: list = []
51
+
52
+ for i in response_dict["data"]:
53
+
54
+ # if re.match(r"^(sz00|sh60)", i["secu_code"]):
55
+ # print(i["secu_code"])
56
+
57
+ # if re.search(r"ST|银行", i["secu_name"]):
58
+ # print(i["secu_name"])
59
+
60
+ # 主板, 非ST, 非银行, 非证券
61
+ if (not re.match(r"^(sz00|sh60)", i["secu_code"])) or re.search(r"ST|银行|证券", i["secu_name"]):
62
+ continue
63
+
64
+ if target in ["up_pool", "up_pool"]:
65
+ result.append({
66
+ "code": stock.coderename(i["secu_code"], restore=True),
67
+ "name": i["secu_name"],
68
+ "up_days": i["limit_up_days"],
69
+ "reason": i["up_reason"]
70
+ })
71
+
72
+ if target in ["up_open_pool", "down_pool"]:
73
+ result.append({
74
+ "code": stock.coderename(i["secu_code"], restore=True),
75
+ "name": i["secu_name"]
76
+ })
77
+
78
+ if utils.v_true(df, bool) is False:
79
+ logger.success(f"{info} [成功]")
80
+ return result
81
+
82
+ # data: pd.DataFrame = pd.DataFrame(response_dict["data"], columns=["secu_code", "secu_name", "limit_up_days", "up_reason"])
83
+ # data = data.rename(columns={"secu_code": "code", "secu_name": "name", "limit_up_days": "up_days", "up_reason": "reason"})
84
+
85
+ return pd.DataFrame(data=pd.DataFrame(result))
86
+
87
+ except Exception as e:
88
+ logger.error(f"{info} [失败]")
89
+ logger.exception(e)
90
+ return None
ezKit/stock.py ADDED
@@ -0,0 +1,61 @@
1
+ """股票"""
2
+ # pylint: disable=R0911
3
+ from copy import deepcopy
4
+ from typing import Any
5
+
6
+ from loguru import logger
7
+
8
+ from . import utils
9
+
10
+
11
+ def coderename(target: str | dict, restore: bool = False) -> str | dict | None:
12
+ """
13
+ 正向:
14
+ coderename('000001') => 'sz000001'
15
+ coderename({'code': '000001', 'name': '平安银行'}) => {'code': 'sz000001', 'name': '平安银行'}
16
+ 反向:
17
+ coderename('sz000001', restore=True) => '000001'
18
+ coderename({'code': 'sz000001', 'name': '平安银行'}) => {'code': '000001', 'name': '平安银行'}
19
+ """
20
+
21
+ try:
22
+
23
+ _object: Any = None
24
+ _code_name: Any = None
25
+
26
+ # 判断 target 是 string 还是 dictionary
27
+ if isinstance(target, str) and utils.v_true(target, str):
28
+ _code_name = target
29
+ elif isinstance(target, dict) and utils.v_true(target, dict):
30
+ _object = deepcopy(target)
31
+ _code_name = str(deepcopy(target["code"]))
32
+ else:
33
+ return None
34
+
35
+ # 是否还原
36
+ if restore:
37
+ if len(_code_name) == 8 and ("sh" in _code_name or "sz" in _code_name):
38
+ _code_name = _code_name[2:8]
39
+ else:
40
+ return None
41
+ else:
42
+ if _code_name[0:2] == "00":
43
+ _code_name = "sz" + _code_name
44
+ elif _code_name[0:2] == "60":
45
+ _code_name = "sh" + _code_name
46
+ else:
47
+ return None
48
+
49
+ # 返回结果
50
+ if utils.v_true(target, str):
51
+ return _code_name
52
+
53
+ if utils.v_true(target, dict):
54
+ _object["code"] = _code_name
55
+ return _object
56
+
57
+ return None
58
+
59
+ except Exception as e:
60
+ logger.exception(e)
61
+ return None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ezKit
3
- Version: 1.8.1
3
+ Version: 1.8.2
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -2,17 +2,19 @@ ezKit/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
2
  ezKit/bottle.py,sha256=usKK1wVaZw4_D-4VwMYmOIc8jtz4TrpM30nck59HMFw,180178
3
3
  ezKit/bottle_extensions.py,sha256=LQikCbbYZBAa4AcihvrTvixWHHMY7OjCBsT02PqWMMM,1129
4
4
  ezKit/cipher.py,sha256=uVUzeoYg5ZPJLpqg2wLst-7vfdDGmqWKka9Oyi0WrCA,2883
5
+ ezKit/cls.py,sha256=mkNSguUNocP8aKh1GEpkUMgL9xRXfMKdGs6tEeeV5X8,3266
5
6
  ezKit/database.py,sha256=awTEdD4aqevyJg5LPBHmUPrOKweqzJ2Ezqqx0_xgUDA,6859
6
7
  ezKit/http.py,sha256=cyS18-TW9f7p1OaiJ4nnVsKZT8Ghy-8OewkfYm8yesw,1790
7
8
  ezKit/mongo.py,sha256=P6WTwFRxaaHixJK_PyKlOfPHkeJRxxrNLV77xy5LVBQ,2048
8
9
  ezKit/qywx.py,sha256=ra2e3u8IJmNZXr569u1mik3KArAiMdC9x0SgXGXEJes,7003
9
10
  ezKit/redis.py,sha256=HVofsLdSBbBHAR-veumsrjTwZQspRDy2FXNR6MDCCXs,1972
10
11
  ezKit/sendemail.py,sha256=Qxu4XQkHRPeX6FSJdzj-MXND9NyKcgHljbafNmy34H0,8243
12
+ ezKit/stock.py,sha256=gEy4N7S0GsZCdfEdYHfaUHMEHMFmNGfHm198hG5n5eI,1754
11
13
  ezKit/token.py,sha256=9CAZhPdXiRiWoOIeWmP0q6L3j1zQAv4YcVWH95Tjefs,1755
12
14
  ezKit/utils.py,sha256=an7joZy_EEpYfN8zBtEWAnhP0YXYfPieabsK_HAxXl4,48921
13
15
  ezKit/xftp.py,sha256=7BABr-gjxZxK2UXoW9XxN76i1HdubeaomYlYMqRurHE,7770
14
- ezKit-1.8.1.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
15
- ezKit-1.8.1.dist-info/METADATA,sha256=hnHRPwzSthfXDscj3YvfPVpNCBe24Z8_xC1vLMY7SR8,190
16
- ezKit-1.8.1.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
17
- ezKit-1.8.1.dist-info/top_level.txt,sha256=aYLB_1WODsqNTsTFWcKP-BN0KCTKcV-HZJ4zlHkCFw8,6
18
- ezKit-1.8.1.dist-info/RECORD,,
16
+ ezKit-1.8.2.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
17
+ ezKit-1.8.2.dist-info/METADATA,sha256=Vnx7icBFnyUYYAHZz3jh5hhDS11d3hHngGlBz-DkWwU,190
18
+ ezKit-1.8.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
19
+ ezKit-1.8.2.dist-info/top_level.txt,sha256=aYLB_1WODsqNTsTFWcKP-BN0KCTKcV-HZJ4zlHkCFw8,6
20
+ ezKit-1.8.2.dist-info/RECORD,,
File without changes
File without changes