ezKit 1.8.7__py3-none-any.whl → 1.9.0__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/bottle_extensions.py +1 -1
- ezKit/cls.py +9 -9
- ezKit/database.py +7 -7
- ezKit/http.py +5 -5
- ezKit/mongo.py +3 -3
- ezKit/qywx.py +2 -2
- ezKit/redis.py +3 -3
- ezKit/sendemail.py +14 -14
- ezKit/stock.py +4 -4
- ezKit/token.py +1 -1
- ezKit/utils.py +255 -448
- {ezKit-1.8.7.dist-info → ezKit-1.9.0.dist-info}/METADATA +1 -1
- ezKit-1.9.0.dist-info/RECORD +20 -0
- ezKit-1.8.7.dist-info/RECORD +0 -20
- {ezKit-1.8.7.dist-info → ezKit-1.9.0.dist-info}/LICENSE +0 -0
- {ezKit-1.8.7.dist-info → ezKit-1.9.0.dist-info}/WHEEL +0 -0
- {ezKit-1.8.7.dist-info → ezKit-1.9.0.dist-info}/top_level.txt +0 -0
ezKit/bottle_extensions.py
CHANGED
ezKit/cls.py
CHANGED
@@ -14,7 +14,7 @@ def up_down_analysis(
|
|
14
14
|
) -> list | pd.DataFrame | None:
|
15
15
|
"""涨停跌停数据"""
|
16
16
|
|
17
|
-
if not utils.
|
17
|
+
if not utils.isTrue(target, str):
|
18
18
|
logger.error(f"error type: {target}")
|
19
19
|
return None
|
20
20
|
|
@@ -75,7 +75,7 @@ def up_down_analysis(
|
|
75
75
|
"name": i["secu_name"]
|
76
76
|
})
|
77
77
|
|
78
|
-
if utils.
|
78
|
+
if not utils.isTrue(df, bool):
|
79
79
|
logger.success(f"{info} [成功]")
|
80
80
|
return result
|
81
81
|
|
@@ -107,7 +107,7 @@ def latest_data(
|
|
107
107
|
case True if True not in [isinstance(payload, str), isinstance(payload, dict)]:
|
108
108
|
logger.error("Incorrect function argument type: payload")
|
109
109
|
return None
|
110
|
-
case True if False in [isinstance(data_type, str), utils.
|
110
|
+
case True if False in [isinstance(data_type, str), utils.isTrue(data_type, str)]:
|
111
111
|
logger.error("Incorrect function argument type: data_type")
|
112
112
|
return None
|
113
113
|
case _:
|
@@ -159,11 +159,11 @@ def latest_data(
|
|
159
159
|
params: dict = {}
|
160
160
|
|
161
161
|
# 默认请求参数
|
162
|
-
if isinstance(payload, str) and utils.
|
162
|
+
if isinstance(payload, str) and utils.isTrue(payload, str):
|
163
163
|
params = {"secu_code": payload}
|
164
164
|
|
165
165
|
# 请求参数
|
166
|
-
if isinstance(payload, dict) and utils.
|
166
|
+
if isinstance(payload, dict) and utils.isTrue(payload, dict):
|
167
167
|
params = payload
|
168
168
|
|
169
169
|
# ------------------------------------------------------------------------------------------
|
@@ -201,7 +201,7 @@ def latest_data(
|
|
201
201
|
response_dict: dict = response.json()
|
202
202
|
|
203
203
|
# 判断数据是否正确
|
204
|
-
if True not in [utils.
|
204
|
+
if True not in [utils.isTrue(response_dict["data"], dict), utils.isTrue(response_dict["data"], list)]:
|
205
205
|
logger.error(f"{info} [失败]")
|
206
206
|
return None
|
207
207
|
|
@@ -217,7 +217,7 @@ def latest_data(
|
|
217
217
|
return None
|
218
218
|
|
219
219
|
# pd.DataFrame 数据
|
220
|
-
if utils.
|
220
|
+
if utils.isTrue(df, bool):
|
221
221
|
df_data = {
|
222
222
|
# "date": [pd.to_datetime(date_today)],
|
223
223
|
"open": [float(response_dict["data"]["open_px"])],
|
@@ -239,7 +239,7 @@ def latest_data(
|
|
239
239
|
# 板块
|
240
240
|
|
241
241
|
# 板块数据不能转换为 pd.DataFrame
|
242
|
-
if (data_type == "plate") and
|
242
|
+
if (data_type == "plate") and utils.isTrue(df, bool):
|
243
243
|
logger.error(f"{info} [错误]")
|
244
244
|
return None
|
245
245
|
|
@@ -267,7 +267,7 @@ def latest_data(
|
|
267
267
|
def plate_codes(plate: str) -> list | None:
|
268
268
|
"""获取板块成分股代码"""
|
269
269
|
|
270
|
-
if utils.
|
270
|
+
if not utils.isTrue(plate, str):
|
271
271
|
logger.error("Incorrect function argument type: plate")
|
272
272
|
return None
|
273
273
|
|
ezKit/database.py
CHANGED
@@ -21,8 +21,8 @@ class Database():
|
|
21
21
|
|
22
22
|
def __init__(self, engine_url, **engine_options):
|
23
23
|
"""Initiation"""
|
24
|
-
if engine_url is not None and utils.
|
25
|
-
if utils.
|
24
|
+
if engine_url is not None and utils.isTrue(engine_url, str):
|
25
|
+
if utils.isTrue(engine_options, dict):
|
26
26
|
self.engine = create_engine(engine_url, **engine_options)
|
27
27
|
else:
|
28
28
|
self.engine = create_engine(engine_url)
|
@@ -117,11 +117,11 @@ class Database():
|
|
117
117
|
|
118
118
|
logger.info(f"{info} ......")
|
119
119
|
|
120
|
-
if utils.
|
120
|
+
if utils.isTrue(sql, str):
|
121
121
|
|
122
122
|
sql_object = sql
|
123
123
|
|
124
|
-
elif sql_file is not None and utils.
|
124
|
+
elif sql_file is not None and utils.isTrue(sql_file, str):
|
125
125
|
|
126
126
|
# 判断文件是否存在
|
127
127
|
if isinstance(sql_file, str) and utils.check_file_type(sql_file, "file") is False:
|
@@ -129,10 +129,10 @@ class Database():
|
|
129
129
|
logger.error(f"No such file: {sql_file}")
|
130
130
|
return False
|
131
131
|
|
132
|
-
if isinstance(sql_file, str) and utils.
|
132
|
+
if isinstance(sql_file, str) and utils.isTrue(sql_file, str):
|
133
133
|
|
134
134
|
# 读取文件内容
|
135
|
-
if sql_file_kwargs is not None and utils.
|
135
|
+
if sql_file_kwargs is not None and utils.isTrue(sql_file_kwargs, dict):
|
136
136
|
with open(sql_file, "r", encoding="utf-8", **sql_file_kwargs) as _file:
|
137
137
|
sql_object = _file.read()
|
138
138
|
else:
|
@@ -179,7 +179,7 @@ class Database():
|
|
179
179
|
logger.info(f"{info_of_save} .......")
|
180
180
|
|
181
181
|
# 保存结果
|
182
|
-
if isinstance(csv_file_kwargs, dict) and utils.
|
182
|
+
if isinstance(csv_file_kwargs, dict) and utils.isTrue(csv_file_kwargs, dict):
|
183
183
|
with open(csv_file, "w", encoding="utf-8", **csv_file_kwargs) as _file:
|
184
184
|
result_of_save = self._result_save(_file, result)
|
185
185
|
else:
|
ezKit/http.py
CHANGED
@@ -17,23 +17,23 @@ def download(
|
|
17
17
|
) -> bool:
|
18
18
|
"""下载文件"""
|
19
19
|
|
20
|
-
if utils.
|
20
|
+
if utils.isTrue(request, dict):
|
21
21
|
request_arguments = {"method": "GET", "stream": True, **request}
|
22
22
|
else:
|
23
23
|
return False
|
24
24
|
|
25
|
-
if utils.
|
25
|
+
if utils.isTrue(file, dict):
|
26
26
|
file_arguments = {"mode": "wb", **file}
|
27
27
|
else:
|
28
28
|
return False
|
29
29
|
|
30
|
-
if iter_content is not None and utils.
|
30
|
+
if iter_content is not None and utils.isTrue(iter_content, dict):
|
31
31
|
iter_content_arguments = {"chunk_size": 1024, **iter_content}
|
32
32
|
else:
|
33
33
|
iter_content_arguments = {"chunk_size": 1024}
|
34
34
|
|
35
35
|
info_prefix: str = "Download"
|
36
|
-
if utils.
|
36
|
+
if utils.isTrue(info, str):
|
37
37
|
info_prefix = f"Download {info}"
|
38
38
|
|
39
39
|
try:
|
@@ -45,7 +45,7 @@ def download(
|
|
45
45
|
# # pylint: disable=W1514
|
46
46
|
with open(**file_arguments) as _file: # type: ignore
|
47
47
|
|
48
|
-
if utils.
|
48
|
+
if utils.isTrue(chunks, bool):
|
49
49
|
for _chunk in response.iter_content(**iter_content_arguments): # type: ignore
|
50
50
|
_file.write(_chunk)
|
51
51
|
else:
|
ezKit/mongo.py
CHANGED
@@ -45,14 +45,14 @@ class Mongo():
|
|
45
45
|
try:
|
46
46
|
logger.info(f"{info} ......")
|
47
47
|
# 是否删除 collection
|
48
|
-
if utils.
|
48
|
+
if utils.isTrue(drop, bool):
|
49
49
|
# 删除 collection
|
50
50
|
db_collection.drop()
|
51
51
|
# 插入数据
|
52
|
-
if utils.
|
52
|
+
if utils.isTrue(data, dict):
|
53
53
|
# 插入一条数据
|
54
54
|
result = db_collection.insert_one(data)
|
55
|
-
elif utils.
|
55
|
+
elif utils.isTrue(data, list):
|
56
56
|
# 插入多条数据
|
57
57
|
result = db_collection.insert_many(data)
|
58
58
|
else:
|
ezKit/qywx.py
CHANGED
@@ -150,9 +150,9 @@ class QYWX:
|
|
150
150
|
users: list = []
|
151
151
|
|
152
152
|
match True:
|
153
|
-
case True if isinstance(mobile, list) and utils.
|
153
|
+
case True if isinstance(mobile, list) and utils.isTrue(mobile, list):
|
154
154
|
users = mobile
|
155
|
-
case True if isinstance(mobile, str) and utils.
|
155
|
+
case True if isinstance(mobile, str) and utils.isTrue(mobile, str):
|
156
156
|
users.append(mobile)
|
157
157
|
case _:
|
158
158
|
return False
|
ezKit/redis.py
CHANGED
@@ -18,9 +18,9 @@ class Redis:
|
|
18
18
|
|
19
19
|
def __init__(self, arguments: str | dict):
|
20
20
|
"""Initiation"""
|
21
|
-
if isinstance(arguments, str) and utils.
|
21
|
+
if isinstance(arguments, str) and utils.isTrue(arguments, str):
|
22
22
|
self.redis = RedisClient.from_url(arguments)
|
23
|
-
elif isinstance(arguments, dict) and utils.
|
23
|
+
elif isinstance(arguments, dict) and utils.isTrue(arguments, dict):
|
24
24
|
self.redis = RedisClient.Redis(**arguments)
|
25
25
|
else:
|
26
26
|
pass
|
@@ -40,7 +40,7 @@ class Redis:
|
|
40
40
|
def flush(self, flushall: bool = False) -> bool:
|
41
41
|
info = "Redis flush"
|
42
42
|
try:
|
43
|
-
if utils.
|
43
|
+
if utils.isTrue(flushall, bool):
|
44
44
|
logger.info(f"{info} all ......")
|
45
45
|
self.redis.flushall()
|
46
46
|
else:
|
ezKit/sendemail.py
CHANGED
@@ -94,7 +94,7 @@ def sendemail(
|
|
94
94
|
|
95
95
|
# 邮件主体
|
96
96
|
|
97
|
-
if utils.
|
97
|
+
if not utils.isTrue(body, dict):
|
98
98
|
logger.error("body error")
|
99
99
|
return False
|
100
100
|
|
@@ -102,7 +102,7 @@ def sendemail(
|
|
102
102
|
|
103
103
|
body_content = cast(str, body.get("content"))
|
104
104
|
|
105
|
-
if utils.
|
105
|
+
if not utils.isTrue(body_content, str):
|
106
106
|
logger.error(f"body content error: {body_content}")
|
107
107
|
return False
|
108
108
|
|
@@ -127,7 +127,7 @@ def sendemail(
|
|
127
127
|
|
128
128
|
# SMTP
|
129
129
|
|
130
|
-
if utils.
|
130
|
+
if not utils.isTrue(smtp, dict):
|
131
131
|
logger.error("smtp error")
|
132
132
|
return False
|
133
133
|
|
@@ -135,21 +135,21 @@ def sendemail(
|
|
135
135
|
smtp_port = cast(int, smtp.get("port"))
|
136
136
|
smtp_tls = cast(bool, smtp.get("tls"))
|
137
137
|
|
138
|
-
if utils.
|
138
|
+
if not utils.isTrue(smtp_host, str):
|
139
139
|
logger.error(f"smtp host error: {smtp_host}")
|
140
140
|
return False
|
141
141
|
|
142
|
-
if utils.
|
142
|
+
if not utils.isTrue(smtp_port, int):
|
143
143
|
logger.error(f"smtp port error: {smtp_port}")
|
144
144
|
return False
|
145
145
|
|
146
|
-
smtp_tls = utils.
|
146
|
+
smtp_tls = utils.isTrue(smtp_tls, bool)
|
147
147
|
|
148
148
|
# ------------------------------------------------------------------------------------------
|
149
149
|
|
150
150
|
# 发件人信息
|
151
151
|
|
152
|
-
if utils.
|
152
|
+
if not utils.isTrue(sender, dict):
|
153
153
|
logger.error("sender error")
|
154
154
|
return False
|
155
155
|
|
@@ -157,15 +157,15 @@ def sendemail(
|
|
157
157
|
sender_address = cast(str, sender.get("address"))
|
158
158
|
sender_password = cast(str, sender.get("password"))
|
159
159
|
|
160
|
-
if utils.
|
160
|
+
if not utils.isTrue(sender_name, str):
|
161
161
|
logger.error(f"sender name error: {sender_name}")
|
162
162
|
return False
|
163
163
|
|
164
|
-
if utils.
|
164
|
+
if not utils.isTrue(sender_address, str):
|
165
165
|
logger.error(f"sender address error: {sender_address}")
|
166
166
|
return False
|
167
167
|
|
168
|
-
if utils.
|
168
|
+
if not utils.isTrue(sender_password, str):
|
169
169
|
logger.error(f"sender password error: {sender_password}")
|
170
170
|
return False
|
171
171
|
|
@@ -175,9 +175,9 @@ def sendemail(
|
|
175
175
|
|
176
176
|
# 收件人(或列表)
|
177
177
|
|
178
|
-
if utils.
|
178
|
+
if utils.isTrue(recipients, str):
|
179
179
|
message["To"] = format_parse(recipients)
|
180
|
-
elif utils.
|
180
|
+
elif utils.isTrue(recipients, list):
|
181
181
|
message["To"] = ", ".join(list(map(format_parse, recipients)))
|
182
182
|
else:
|
183
183
|
logger.error("recipients error")
|
@@ -187,7 +187,7 @@ def sendemail(
|
|
187
187
|
|
188
188
|
# 邮件主题
|
189
189
|
|
190
|
-
if utils.
|
190
|
+
if not utils.isTrue(subject, str):
|
191
191
|
logger.error("subject error")
|
192
192
|
return False
|
193
193
|
|
@@ -195,7 +195,7 @@ def sendemail(
|
|
195
195
|
|
196
196
|
# ------------------------------------------------------------------------------------------
|
197
197
|
|
198
|
-
if images is not None and utils.
|
198
|
+
if images is not None and utils.isTrue(images, list):
|
199
199
|
|
200
200
|
for image in images:
|
201
201
|
|
ezKit/stock.py
CHANGED
@@ -23,9 +23,9 @@ def coderename(target: str | dict, restore: bool = False) -> str | dict | None:
|
|
23
23
|
_code_name: Any = None
|
24
24
|
|
25
25
|
# 判断 target 是 string 还是 dictionary
|
26
|
-
if isinstance(target, str) and utils.
|
26
|
+
if isinstance(target, str) and utils.isTrue(target, str):
|
27
27
|
_code_name = target
|
28
|
-
elif isinstance(target, dict) and utils.
|
28
|
+
elif isinstance(target, dict) and utils.isTrue(target, dict):
|
29
29
|
_object = deepcopy(target)
|
30
30
|
_code_name = str(deepcopy(target["code"]))
|
31
31
|
else:
|
@@ -46,10 +46,10 @@ def coderename(target: str | dict, restore: bool = False) -> str | dict | None:
|
|
46
46
|
return None
|
47
47
|
|
48
48
|
# 返回结果
|
49
|
-
if utils.
|
49
|
+
if utils.isTrue(target, str):
|
50
50
|
return _code_name
|
51
51
|
|
52
|
-
if utils.
|
52
|
+
if utils.isTrue(target, dict):
|
53
53
|
_object["code"] = _code_name
|
54
54
|
return _object
|
55
55
|
|
ezKit/token.py
CHANGED
@@ -38,7 +38,7 @@ def generate_token(key: str = 'Fc0zXCmGKd7tPu6W', timeout: int = 3600, data: Any
|
|
38
38
|
|
39
39
|
def parsing_token(token_string: str, key: str = 'Fc0zXCmGKd7tPu6W') -> (dict | None):
|
40
40
|
try:
|
41
|
-
if utils.
|
41
|
+
if not utils.isTrue(token_string, str):
|
42
42
|
return None
|
43
43
|
|
44
44
|
aes_cipher = cipher.AESCipher(key=key, algorithm='sha256')
|