ezKit 2.0.4__tar.gz → 2.0.6__tar.gz
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-2.0.4/ezKit.egg-info → ezkit-2.0.6}/PKG-INFO +1 -1
- ezkit-2.0.6/ezKit/stock.py +85 -0
- ezkit-2.0.6/ezKit/utils.py +145 -0
- {ezkit-2.0.4 → ezkit-2.0.6/ezKit.egg-info}/PKG-INFO +1 -1
- {ezkit-2.0.4 → ezkit-2.0.6}/ezKit.egg-info/SOURCES.txt +1 -0
- {ezkit-2.0.4 → ezkit-2.0.6}/setup.py +1 -1
- ezkit-2.0.4/ezKit/utils.py +0 -46
- {ezkit-2.0.4 → ezkit-2.0.6}/LICENSE +0 -0
- {ezkit-2.0.4 → ezkit-2.0.6}/MANIFEST.in +0 -0
- {ezkit-2.0.4 → ezkit-2.0.6}/README.md +0 -0
- {ezkit-2.0.4 → ezkit-2.0.6}/ezKit/__init__.py +0 -0
- {ezkit-2.0.4 → ezkit-2.0.6}/ezKit/database.py +0 -0
- {ezkit-2.0.4 → ezkit-2.0.6}/ezKit/http.py +0 -0
- {ezkit-2.0.4 → ezkit-2.0.6}/ezKit/redix.py +0 -0
- {ezkit-2.0.4 → ezkit-2.0.6}/ezKit.egg-info/dependency_links.txt +0 -0
- {ezkit-2.0.4 → ezkit-2.0.6}/ezKit.egg-info/requires.txt +0 -0
- {ezkit-2.0.4 → ezkit-2.0.6}/ezKit.egg-info/top_level.txt +0 -0
- {ezkit-2.0.4 → ezkit-2.0.6}/pyproject.toml +0 -0
- {ezkit-2.0.4 → ezkit-2.0.6}/setup.cfg +0 -0
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"""股票"""
|
|
2
|
+
|
|
3
|
+
from copy import deepcopy
|
|
4
|
+
from os import environ
|
|
5
|
+
|
|
6
|
+
from loguru import logger
|
|
7
|
+
|
|
8
|
+
# --------------------------------------------------------------------------------------------------
|
|
9
|
+
|
|
10
|
+
DEBUG = environ.get("DEBUG")
|
|
11
|
+
|
|
12
|
+
# --------------------------------------------------------------------------------------------------
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def coderename(target: str | dict, restore: bool = False) -> str | dict | None:
|
|
16
|
+
"""代码重命名"""
|
|
17
|
+
|
|
18
|
+
# 正向:
|
|
19
|
+
# coderename('000001') => 'sz000001'
|
|
20
|
+
# coderename({'code': '000001', 'name': '平安银行'}) => {'code': 'sz000001', 'name': '平安银行'}
|
|
21
|
+
# 反向:
|
|
22
|
+
# coderename('sz000001', restore=True) => '000001'
|
|
23
|
+
# coderename({'code': 'sz000001', 'name': '平安银行'}) => {'code': '000001', 'name': '平安银行'}
|
|
24
|
+
|
|
25
|
+
try:
|
|
26
|
+
|
|
27
|
+
# 初始化
|
|
28
|
+
|
|
29
|
+
code_object: dict = {}
|
|
30
|
+
code_name: str = ""
|
|
31
|
+
|
|
32
|
+
# 判断 target
|
|
33
|
+
|
|
34
|
+
if isinstance(target, str) and target:
|
|
35
|
+
code_name = target
|
|
36
|
+
elif isinstance(target, dict) and target:
|
|
37
|
+
code_object = deepcopy(target)
|
|
38
|
+
code_name = code_object.get("code", "")
|
|
39
|
+
else:
|
|
40
|
+
logger.error("target value or type error")
|
|
41
|
+
return None
|
|
42
|
+
|
|
43
|
+
if not code_name:
|
|
44
|
+
logger.error("code name error")
|
|
45
|
+
return None
|
|
46
|
+
|
|
47
|
+
# 是否还原
|
|
48
|
+
|
|
49
|
+
if restore:
|
|
50
|
+
|
|
51
|
+
if len(code_name) != 8 or not code_name.startswith(("sz", "sh")):
|
|
52
|
+
logger.error("code name error")
|
|
53
|
+
return None
|
|
54
|
+
|
|
55
|
+
code_name = code_name[-6:]
|
|
56
|
+
|
|
57
|
+
else:
|
|
58
|
+
|
|
59
|
+
if code_name[0:2] == "00":
|
|
60
|
+
code_name = f"sz{code_name}"
|
|
61
|
+
elif code_name[0:2] == "60":
|
|
62
|
+
code_name = f"sh{code_name}"
|
|
63
|
+
else:
|
|
64
|
+
logger.error("code name error")
|
|
65
|
+
return None
|
|
66
|
+
|
|
67
|
+
# 返回结果
|
|
68
|
+
|
|
69
|
+
if isinstance(target, str):
|
|
70
|
+
return code_name
|
|
71
|
+
|
|
72
|
+
if isinstance(target, dict):
|
|
73
|
+
code_object["code"] = code_name
|
|
74
|
+
return code_object
|
|
75
|
+
|
|
76
|
+
return None
|
|
77
|
+
|
|
78
|
+
except Exception as e:
|
|
79
|
+
|
|
80
|
+
if DEBUG:
|
|
81
|
+
logger.exception(e)
|
|
82
|
+
else:
|
|
83
|
+
logger.error(e)
|
|
84
|
+
|
|
85
|
+
return None
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""Utils Library"""
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
import tomllib
|
|
5
|
+
|
|
6
|
+
from os import environ
|
|
7
|
+
from typing import Iterable
|
|
8
|
+
|
|
9
|
+
from loguru import logger
|
|
10
|
+
|
|
11
|
+
# --------------------------------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
DEBUG = environ.get("DEBUG")
|
|
14
|
+
|
|
15
|
+
# --------------------------------------------------------------------------------------------------
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def load_toml_file(file: str) -> dict:
|
|
19
|
+
"""Load TOML file"""
|
|
20
|
+
|
|
21
|
+
info: str = "load toml file"
|
|
22
|
+
|
|
23
|
+
try:
|
|
24
|
+
|
|
25
|
+
logger.info(f"{info} [ start ]")
|
|
26
|
+
|
|
27
|
+
# 不要加 encoding="utf-8" 参数, 否则会报错:
|
|
28
|
+
# binary mode doesn't take an encoding argument
|
|
29
|
+
with open(file, "rb") as _file:
|
|
30
|
+
config = tomllib.load(_file)
|
|
31
|
+
|
|
32
|
+
logger.success(f"{info} [ success ]")
|
|
33
|
+
|
|
34
|
+
return config
|
|
35
|
+
|
|
36
|
+
except Exception as e:
|
|
37
|
+
|
|
38
|
+
logger.error(f"{info} [ error ]")
|
|
39
|
+
|
|
40
|
+
if DEBUG:
|
|
41
|
+
logger.exception(e)
|
|
42
|
+
else:
|
|
43
|
+
logger.error(e)
|
|
44
|
+
|
|
45
|
+
return {}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# --------------------------------------------------------------------------------------------------
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def check_dict_values_incorrect(
|
|
52
|
+
data: dict[str, object],
|
|
53
|
+
errors: object | Iterable[object] | None = None,
|
|
54
|
+
include_keys: list[str] | None = None,
|
|
55
|
+
exclude_keys: list[str] | None = None,
|
|
56
|
+
regex: str | None = None,
|
|
57
|
+
) -> bool:
|
|
58
|
+
"""检查字典的值是否存在错误值"""
|
|
59
|
+
|
|
60
|
+
# 支持:
|
|
61
|
+
#
|
|
62
|
+
# target: 单值 或 多值(列表/元组)
|
|
63
|
+
# regex: 值是否匹配某正则表达式
|
|
64
|
+
# include_keys / exclude_keys: 指定检查的 key 范围
|
|
65
|
+
#
|
|
66
|
+
# 匹配规则(满足任一条件即可):
|
|
67
|
+
#
|
|
68
|
+
# value 等于 target 或 在 target 列表里
|
|
69
|
+
# value 与 regex 匹配
|
|
70
|
+
#
|
|
71
|
+
# 参数:
|
|
72
|
+
#
|
|
73
|
+
# data dict[str, object] 待检查的字典
|
|
74
|
+
# errors object|Iterable|None 指定匹配值或值列表
|
|
75
|
+
# include_keys list[str]|None 只检查这些 key
|
|
76
|
+
# exclude_keys list[str]|None 排除指定 key
|
|
77
|
+
# regex str|None 正则匹配(自动转换成 re.Pattern)
|
|
78
|
+
#
|
|
79
|
+
# 返回:
|
|
80
|
+
#
|
|
81
|
+
# bool
|
|
82
|
+
#
|
|
83
|
+
# 所有最终 keys 的值满足任一匹配条件返回 False, 否则 True
|
|
84
|
+
|
|
85
|
+
try:
|
|
86
|
+
|
|
87
|
+
# -----------------------
|
|
88
|
+
# 处理 include / exclude 逻辑
|
|
89
|
+
# -----------------------
|
|
90
|
+
if include_keys is not None:
|
|
91
|
+
keys = set(include_keys)
|
|
92
|
+
else:
|
|
93
|
+
keys = set(data.keys())
|
|
94
|
+
|
|
95
|
+
if exclude_keys is not None:
|
|
96
|
+
keys -= set(exclude_keys)
|
|
97
|
+
|
|
98
|
+
# 若没有 key 需要检查 -> 默认 True
|
|
99
|
+
if not keys:
|
|
100
|
+
return False
|
|
101
|
+
|
|
102
|
+
# -----------------------
|
|
103
|
+
# 处理 target(单值 or 列表)
|
|
104
|
+
# -----------------------
|
|
105
|
+
if isinstance(errors, Iterable) and not isinstance(errors, (str, bytes)):
|
|
106
|
+
error_set = set(errors)
|
|
107
|
+
else:
|
|
108
|
+
error_set = {errors}
|
|
109
|
+
|
|
110
|
+
# -----------------------
|
|
111
|
+
# 处理正则
|
|
112
|
+
# -----------------------
|
|
113
|
+
pattern = re.compile(regex) if regex else None
|
|
114
|
+
|
|
115
|
+
# -----------------------
|
|
116
|
+
# 核心检查逻辑
|
|
117
|
+
# -----------------------
|
|
118
|
+
for k in keys:
|
|
119
|
+
|
|
120
|
+
value = data.get(k)
|
|
121
|
+
|
|
122
|
+
# 匹配 target
|
|
123
|
+
if value in error_set:
|
|
124
|
+
return False
|
|
125
|
+
|
|
126
|
+
# 匹配 类型
|
|
127
|
+
# if isinstance(types, list) and types:
|
|
128
|
+
# if any(isinstance(value, type) for type in types):
|
|
129
|
+
# return False
|
|
130
|
+
|
|
131
|
+
# 匹配正则
|
|
132
|
+
if pattern is not None:
|
|
133
|
+
if isinstance(value, str) and pattern.search(value):
|
|
134
|
+
return False
|
|
135
|
+
|
|
136
|
+
return True
|
|
137
|
+
|
|
138
|
+
except Exception as e:
|
|
139
|
+
|
|
140
|
+
if DEBUG:
|
|
141
|
+
logger.exception(e)
|
|
142
|
+
else:
|
|
143
|
+
logger.error(e)
|
|
144
|
+
|
|
145
|
+
return False
|
ezkit-2.0.4/ezKit/utils.py
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
"""Utils Library"""
|
|
2
|
-
|
|
3
|
-
import tomllib
|
|
4
|
-
|
|
5
|
-
from os import environ
|
|
6
|
-
|
|
7
|
-
from loguru import logger
|
|
8
|
-
|
|
9
|
-
# --------------------------------------------------------------------------------------------------
|
|
10
|
-
|
|
11
|
-
DEBUG = environ.get("DEBUG")
|
|
12
|
-
|
|
13
|
-
# --------------------------------------------------------------------------------------------------
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def load_toml_file(file: str) -> dict:
|
|
17
|
-
"""Load TOML file"""
|
|
18
|
-
|
|
19
|
-
info: str = "load toml file"
|
|
20
|
-
|
|
21
|
-
try:
|
|
22
|
-
|
|
23
|
-
logger.info(f"{info} [ start ]")
|
|
24
|
-
|
|
25
|
-
# 不要加 encoding="utf-8" 参数, 否则会报错:
|
|
26
|
-
# binary mode doesn't take an encoding argument
|
|
27
|
-
with open(file, "rb") as _file:
|
|
28
|
-
config = tomllib.load(_file)
|
|
29
|
-
|
|
30
|
-
logger.success(f"{info} [ success ]")
|
|
31
|
-
|
|
32
|
-
return config
|
|
33
|
-
|
|
34
|
-
except Exception as e:
|
|
35
|
-
|
|
36
|
-
logger.error(f"{info} [ error ]")
|
|
37
|
-
|
|
38
|
-
if DEBUG:
|
|
39
|
-
logger.exception(e)
|
|
40
|
-
else:
|
|
41
|
-
logger.error(e)
|
|
42
|
-
|
|
43
|
-
return {}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
# --------------------------------------------------------------------------------------------------
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|