ezKit 1.8.8__py3-none-any.whl → 1.9.1__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.
@@ -24,7 +24,7 @@ def request_json() -> bottle.DictProperty | None:
24
24
  """Bottle Request JSON"""
25
25
  try:
26
26
  data = bottle.request.json
27
- if utils.v_true(data, dict):
27
+ if utils.isTrue(data, dict):
28
28
  return data
29
29
  return None
30
30
  except Exception as e:
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.v_true(target, str):
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.v_true(df, bool) is False:
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.v_true(data_type, str)]:
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.v_true(payload, str):
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.v_true(payload, dict):
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.v_true(response_dict["data"], dict), utils.v_true(response_dict["data"], list)]:
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.v_true(df, bool) is True:
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 (utils.v_true(df, bool) is True):
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.v_true(plate, str) is False:
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
@@ -10,6 +10,7 @@ from typing import Any
10
10
 
11
11
  from loguru import logger
12
12
  from sqlalchemy import CursorResult, Index, create_engine, text
13
+ from sqlalchemy.orm import DeclarativeBase
13
14
 
14
15
  from . import utils
15
16
 
@@ -19,13 +20,13 @@ class Database():
19
20
 
20
21
  engine = create_engine('sqlite://')
21
22
 
22
- def __init__(self, engine_url, **engine_options):
23
+ def __init__(self, target: str, **options):
23
24
  """Initiation"""
24
- if engine_url is not None and utils.v_true(engine_url, str):
25
- if utils.v_true(engine_options, dict):
26
- self.engine = create_engine(engine_url, **engine_options)
25
+ if isinstance(target, str) and utils.isTrue(target, str):
26
+ if utils.isTrue(options, dict):
27
+ self.engine = create_engine(target, **options)
27
28
  else:
28
- self.engine = create_engine(engine_url)
29
+ self.engine = create_engine(target)
29
30
  else:
30
31
  pass
31
32
 
@@ -45,7 +46,7 @@ class Database():
45
46
  logger.exception(e)
46
47
  return False
47
48
 
48
- def metadata_init(self, base, **kwargs) -> bool:
49
+ def metadata_init(self, base: DeclarativeBase, **kwargs) -> bool:
49
50
  # https://stackoverflow.com/questions/19175311/how-to-create-only-one-table-with-sqlalchemy
50
51
  info = "Database init table"
51
52
  try:
@@ -117,11 +118,11 @@ class Database():
117
118
 
118
119
  logger.info(f"{info} ......")
119
120
 
120
- if utils.v_true(sql, str):
121
+ if utils.isTrue(sql, str):
121
122
 
122
123
  sql_object = sql
123
124
 
124
- elif sql_file is not None and utils.v_true(sql_file, str):
125
+ elif sql_file is not None and utils.isTrue(sql_file, str):
125
126
 
126
127
  # 判断文件是否存在
127
128
  if isinstance(sql_file, str) and utils.check_file_type(sql_file, "file") is False:
@@ -129,10 +130,10 @@ class Database():
129
130
  logger.error(f"No such file: {sql_file}")
130
131
  return False
131
132
 
132
- if isinstance(sql_file, str) and utils.v_true(sql_file, str):
133
+ if isinstance(sql_file, str) and utils.isTrue(sql_file, str):
133
134
 
134
135
  # 读取文件内容
135
- if sql_file_kwargs is not None and utils.v_true(sql_file_kwargs, dict):
136
+ if sql_file_kwargs is not None and utils.isTrue(sql_file_kwargs, dict):
136
137
  with open(sql_file, "r", encoding="utf-8", **sql_file_kwargs) as _file:
137
138
  sql_object = _file.read()
138
139
  else:
@@ -179,7 +180,7 @@ class Database():
179
180
  logger.info(f"{info_of_save} .......")
180
181
 
181
182
  # 保存结果
182
- if isinstance(csv_file_kwargs, dict) and utils.v_true(csv_file_kwargs, dict):
183
+ if isinstance(csv_file_kwargs, dict) and utils.isTrue(csv_file_kwargs, dict):
183
184
  with open(csv_file, "w", encoding="utf-8", **csv_file_kwargs) as _file:
184
185
  result_of_save = self._result_save(_file, result)
185
186
  else:
ezKit/http.py CHANGED
@@ -17,23 +17,23 @@ def download(
17
17
  ) -> bool:
18
18
  """下载文件"""
19
19
 
20
- if utils.v_true(request, dict):
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.v_true(file, dict):
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.v_true(iter_content, dict):
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.v_true(info, str):
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.v_true(chunks, bool):
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
@@ -11,6 +11,15 @@ class Mongo():
11
11
 
12
12
  client = MongoClient()
13
13
 
14
+ def __init__(self, target: str | dict):
15
+ """Initiation"""
16
+ if isinstance(target, str) and utils.isTrue(target, str):
17
+ self.client = MongoClient(target)
18
+ elif isinstance(target, dict) and utils.isTrue(target, dict):
19
+ self.client = MongoClient(**target)
20
+ else:
21
+ pass
22
+
14
23
  def close(self) -> bool:
15
24
  """client close"""
16
25
  try:
@@ -45,14 +54,14 @@ class Mongo():
45
54
  try:
46
55
  logger.info(f"{info} ......")
47
56
  # 是否删除 collection
48
- if utils.v_true(drop, bool):
57
+ if utils.isTrue(drop, bool):
49
58
  # 删除 collection
50
59
  db_collection.drop()
51
60
  # 插入数据
52
- if utils.v_true(data, dict):
61
+ if utils.isTrue(data, dict):
53
62
  # 插入一条数据
54
63
  result = db_collection.insert_one(data)
55
- elif utils.v_true(data, list):
64
+ elif utils.isTrue(data, list):
56
65
  # 插入多条数据
57
66
  result = db_collection.insert_many(data)
58
67
  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.v_true(mobile, list):
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.v_true(mobile, str):
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
@@ -16,12 +16,12 @@ class Redis:
16
16
  # 这里修改以下参数: host, port, socket_timeout, socket_connect_timeout, charset
17
17
  redis = RedisClient.Redis()
18
18
 
19
- def __init__(self, arguments: str | dict):
19
+ def __init__(self, target: str | dict):
20
20
  """Initiation"""
21
- if isinstance(arguments, str) and utils.v_true(arguments, str):
22
- self.redis = RedisClient.from_url(arguments)
23
- elif isinstance(arguments, dict) and utils.v_true(arguments, dict):
24
- self.redis = RedisClient.Redis(**arguments)
21
+ if isinstance(target, str) and utils.isTrue(target, str):
22
+ self.redis = RedisClient.from_url(target)
23
+ elif isinstance(target, dict) and utils.isTrue(target, dict):
24
+ self.redis = RedisClient.Redis(**target)
25
25
  else:
26
26
  pass
27
27
 
@@ -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.v_true(flushall, bool):
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.v_true(body, dict) is False:
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.v_true(body_content, str) is False:
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.v_true(smtp, dict) is False:
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.v_true(smtp_host, str) is False:
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.v_true(smtp_port, int) is False:
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.v_true(smtp_tls, bool)
146
+ smtp_tls = utils.isTrue(smtp_tls, bool)
147
147
 
148
148
  # ------------------------------------------------------------------------------------------
149
149
 
150
150
  # 发件人信息
151
151
 
152
- if utils.v_true(sender, dict) is False:
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.v_true(sender_name, str) is False:
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.v_true(sender_address, str) is False:
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.v_true(sender_password, str) is False:
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.v_true(recipients, str):
178
+ if utils.isTrue(recipients, str):
179
179
  message["To"] = format_parse(recipients)
180
- elif utils.v_true(recipients, list):
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.v_true(subject, str) is False:
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.v_true(images, list):
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.v_true(target, str):
26
+ if isinstance(target, str) and utils.isTrue(target, str):
27
27
  _code_name = target
28
- elif isinstance(target, dict) and utils.v_true(target, dict):
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.v_true(target, str):
49
+ if utils.isTrue(target, str):
50
50
  return _code_name
51
51
 
52
- if utils.v_true(target, dict):
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.v_true(token_string, str) is False:
41
+ if not utils.isTrue(token_string, str):
42
42
  return None
43
43
 
44
44
  aes_cipher = cipher.AESCipher(key=key, algorithm='sha256')