ezKit 1.9.7__py3-none-any.whl → 1.9.9__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/database.py +10 -8
- ezKit/utils.py +35 -67
- {ezKit-1.9.7.dist-info → ezKit-1.9.9.dist-info}/METADATA +1 -1
- {ezKit-1.9.7.dist-info → ezKit-1.9.9.dist-info}/RECORD +7 -7
- {ezKit-1.9.7.dist-info → ezKit-1.9.9.dist-info}/LICENSE +0 -0
- {ezKit-1.9.7.dist-info → ezKit-1.9.9.dist-info}/WHEEL +0 -0
- {ezKit-1.9.7.dist-info → ezKit-1.9.9.dist-info}/top_level.txt +0 -0
ezKit/database.py
CHANGED
@@ -101,19 +101,17 @@ class Database():
|
|
101
101
|
csv_file: str | None = None,
|
102
102
|
csv_file_kwargs: dict | None = None
|
103
103
|
) -> CursorResult[Any] | bool:
|
104
|
-
"""
|
105
|
-
echo 是否打印日志
|
106
|
-
某些情况下只需要结果, 不需要日志, 将 echo 设置为 False 即可
|
107
|
-
"""
|
108
|
-
|
109
|
-
# info_prefix = '[Execute SQL]'
|
104
|
+
""""运行"""
|
110
105
|
|
111
106
|
# ------------------------------------------------------------
|
112
107
|
|
113
108
|
# 提取 SQL
|
114
109
|
# 如果 sql 和 sql_file 同时存在, 优先执行 sql
|
110
|
+
|
115
111
|
sql_object = None
|
116
|
-
|
112
|
+
|
113
|
+
info: str = f"""Extract SQL: {sql}"""
|
114
|
+
|
117
115
|
try:
|
118
116
|
|
119
117
|
logger.info(f"{info} ......")
|
@@ -157,7 +155,9 @@ class Database():
|
|
157
155
|
# ------------------------------------------------------------
|
158
156
|
|
159
157
|
# 执行 SQL
|
160
|
-
|
158
|
+
|
159
|
+
info = f"""Execute SQL: {sql_object}"""
|
160
|
+
|
161
161
|
try:
|
162
162
|
|
163
163
|
logger.info(f"{info} ......")
|
@@ -170,6 +170,8 @@ class Database():
|
|
170
170
|
|
171
171
|
result = connect.execute(text(sql_object))
|
172
172
|
|
173
|
+
connect.commit()
|
174
|
+
|
173
175
|
if csv_file is None:
|
174
176
|
# 如果 csv_file 没有定义, 则直接返回结果
|
175
177
|
logger.success(f'{info} [success]')
|
ezKit/utils.py
CHANGED
@@ -8,6 +8,7 @@ import subprocess
|
|
8
8
|
import time
|
9
9
|
import tomllib
|
10
10
|
from copy import deepcopy
|
11
|
+
from itertools import islice
|
11
12
|
from multiprocessing import Pool, Process
|
12
13
|
from multiprocessing.pool import ThreadPool
|
13
14
|
from pathlib import Path
|
@@ -352,90 +353,57 @@ def list_dict_sorted_by_key(
|
|
352
353
|
logger.exception(e)
|
353
354
|
return None
|
354
355
|
|
355
|
-
|
356
356
|
def list_split(
|
357
357
|
data: list,
|
358
358
|
number: int,
|
359
359
|
equally: bool = False
|
360
360
|
) -> list | None:
|
361
|
-
"""
|
361
|
+
"""列表分割"""
|
362
|
+
|
362
363
|
# 列表分割
|
363
364
|
#
|
364
|
-
# 默认: 将 list 以 number
|
365
|
-
#
|
366
|
-
# data = [1, 2, 3, 4, 5, 6, 7]
|
367
|
-
#
|
368
|
-
# list_split(data, 2) -> 将 data 以 2个元素为一个 list 分割
|
369
|
-
# [[1, 2], [3, 4], [5, 6], [7]]
|
365
|
+
# 默认: 将 list 以 number 个元素为一个子 list 分割
|
370
366
|
#
|
371
|
-
#
|
372
|
-
#
|
367
|
+
# data = [1, 2, 3, 4, 5, 6, 7] 奇数个元素
|
368
|
+
# list_split(data, 2) -> [[1, 2], [3, 4], [5, 6], [7]] 将 data 以 2个元素 为一个 list 分割
|
369
|
+
# list_split(data, 3) -> [[1, 2, 3], [4, 5, 6], [7]] 将 data 以 3个元素 为一个 list 分割
|
373
370
|
#
|
374
|
-
#
|
371
|
+
# data = [1, 2, 3, 4, 5, 6, 7, 8] 偶数个元素
|
372
|
+
# list_split(data, 2) -> [[1, 2], [3, 4], [5, 6], [7, 8]] 将 data 以 2个元素 为一个 list 分割
|
373
|
+
# list_split(data, 3) -> [[1, 2, 3], [4, 5, 6], [7, 8]] 将 data 以 3个元素 为一个 list 分割
|
375
374
|
#
|
376
|
-
#
|
375
|
+
# equally 为 True 时, 将 list 平均分成 number 个元素的子 list
|
377
376
|
#
|
378
|
-
#
|
379
|
-
#
|
377
|
+
# data = [1, 2, 3, 4, 5, 6, 7] 奇数个元素
|
378
|
+
# list_split(data, 2, True) -> [[1, 2, 3, 4], [5, 6, 7]] 将 data 平均分成 2个子list
|
379
|
+
# list_split(data, 3, True) -> [[1, 2, 3], [4, 5, 6], [7]] 将 data 平均分成 3个子list
|
380
380
|
#
|
381
|
-
#
|
382
|
-
#
|
383
|
-
#
|
384
|
-
# list_split_equally(data, 7) -> 将 data 平均分成 7 份
|
385
|
-
# [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12], [13, 14, 15], [16, 17], [18, 19]]
|
386
|
-
|
387
|
-
try:
|
388
|
-
|
389
|
-
# 数据拷贝
|
390
|
-
_data_object = deepcopy(data)
|
381
|
+
# data = [1, 2, 3, 4, 5, 6, 7, 8] 偶数个元素
|
382
|
+
# list_split(data, 2, True) -> [[1, 2, 3, 4], [5, 6, 7, 8]] 将 data 平均分成 2个子list
|
383
|
+
# list_split(data, 3, True) -> [[1, 2, 3], [4, 5, 6], [7, 8]] 将 data 平均分成 3个子list
|
391
384
|
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
_data_result = []
|
397
|
-
|
398
|
-
_step_number: Optional[int] = None
|
399
|
-
|
400
|
-
if _data_length < number:
|
385
|
+
# 判断参数是否正确
|
386
|
+
match True:
|
387
|
+
case True if not isTrue(data, list):
|
388
|
+
logger.error("argument error: data")
|
401
389
|
return None
|
390
|
+
case True if not isTrue(number, int):
|
391
|
+
logger.error("argument error: number")
|
392
|
+
return None
|
393
|
+
case _:
|
394
|
+
pass
|
402
395
|
|
403
|
-
|
404
|
-
|
405
|
-
_data_result = [[i] for i in _data_object]
|
406
|
-
|
407
|
-
else:
|
408
|
-
|
409
|
-
if isTrue(equally, bool):
|
410
|
-
|
411
|
-
_step_number = step_number_for_split_equally(_data_length, number)
|
412
|
-
|
413
|
-
if _data_length % number == 0:
|
414
|
-
|
415
|
-
index_number_list = list(range(0, _data_length, number))
|
416
|
-
for index_number in index_number_list:
|
417
|
-
_data_result.append(deepcopy(_data_object[index_number:index_number + number]))
|
418
|
-
|
419
|
-
else:
|
420
|
-
|
421
|
-
# 前一部分
|
422
|
-
if _step_number is not None:
|
423
|
-
previous_end_number = (_data_length % number) * _step_number
|
424
|
-
previous_index_number_list = list(range(0, previous_end_number, _step_number))
|
425
|
-
for index_number in previous_index_number_list:
|
426
|
-
_data_result.append(deepcopy(_data_object[index_number:index_number + _step_number]))
|
427
|
-
|
428
|
-
# 后一部分
|
429
|
-
next_number_list = list(range(previous_end_number, _data_length, _step_number - 1))
|
430
|
-
for index_number in next_number_list:
|
431
|
-
_data_result.append(deepcopy(_data_object[index_number:index_number + (_step_number - 1)]))
|
432
|
-
|
433
|
-
else:
|
396
|
+
try:
|
434
397
|
|
435
|
-
|
436
|
-
|
398
|
+
# 要将列表平均分成 n 个子列表
|
399
|
+
if isTrue(equally, bool):
|
400
|
+
it = iter(data)
|
401
|
+
chunk_size = (len(data) + number - 1) // number # 每组至少多少个元素
|
402
|
+
return [list(islice(it, chunk_size)) for _ in range(number)]
|
437
403
|
|
438
|
-
|
404
|
+
# 将列表按每 n 个元素为一个列表进行分割
|
405
|
+
it = iter(data)
|
406
|
+
return [list(islice(it, number)) for _ in range((len(data) + number - 1) // number)]
|
439
407
|
|
440
408
|
except Exception as e:
|
441
409
|
logger.exception(e)
|
@@ -3,7 +3,7 @@ ezKit/bottle.py,sha256=usKK1wVaZw4_D-4VwMYmOIc8jtz4TrpM30nck59HMFw,180178
|
|
3
3
|
ezKit/bottle_extensions.py,sha256=3reEQVZuHklXTl6r7F8kiBFFPb0RaAGc3mYJJnrMDjQ,1129
|
4
4
|
ezKit/cipher.py,sha256=0T_StbjiNI4zgrjVgcfU-ffKgu1waBA9UDudAnqFcNM,2896
|
5
5
|
ezKit/cls.py,sha256=e7_72kv0Q_o023xcjKNtrkfKg7frABQvCF_JjoHV94U,10800
|
6
|
-
ezKit/database.py,sha256=
|
6
|
+
ezKit/database.py,sha256=Rc4RgjHOOtf5dMLvMkK1beRfbIai5E1x4HTsDwKsA-Q,6822
|
7
7
|
ezKit/http.py,sha256=i3Kn5AMAMicDMcDjxKKZU7zqEKTU88Ec9_LwCuBJy-0,1801
|
8
8
|
ezKit/mongo.py,sha256=dOm_1wXEPp_e8Ml5Qq78M7FDNrQUAZaThzVIiiLJJwk,2393
|
9
9
|
ezKit/qywx.py,sha256=X_H4fzP-iEqeDEbumr7D1bXi6dxczaxfO8iyutzy02s,7171
|
@@ -11,10 +11,10 @@ ezKit/redis.py,sha256=g2_V4jvq0djRc20jLZkgeAeF_bYrq-Rbl_kHcCUPZcA,1965
|
|
11
11
|
ezKit/sendemail.py,sha256=tRXCsJm_RfTJ9xEWe_lTQ5kOs2JxHGPXvq0oWA7prq0,7263
|
12
12
|
ezKit/stock.py,sha256=cbL0ZXCur4G290wFN5ynmLmMjgDRNSvVQgsE_0jSQKU,11802
|
13
13
|
ezKit/token.py,sha256=HKREyZj_T2S8-aFoFIrBXTaCKExQq4zE66OHXhGHqQg,1750
|
14
|
-
ezKit/utils.py,sha256
|
14
|
+
ezKit/utils.py,sha256=H-VaWzH1TkpJe_lpPBW2yaP6R7NElDbHRTsByRj_t9w,43234
|
15
15
|
ezKit/xftp.py,sha256=XyIdr_2rxRVLqPofG6fIYWhAMVsFwTyp46dg5P9FLW4,7774
|
16
|
-
ezKit-1.9.
|
17
|
-
ezKit-1.9.
|
18
|
-
ezKit-1.9.
|
19
|
-
ezKit-1.9.
|
20
|
-
ezKit-1.9.
|
16
|
+
ezKit-1.9.9.dist-info/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
17
|
+
ezKit-1.9.9.dist-info/METADATA,sha256=i9NRcyP11nSCxo9bCngbdreKObAoIebkPJz5Sh1EiR0,190
|
18
|
+
ezKit-1.9.9.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
|
19
|
+
ezKit-1.9.9.dist-info/top_level.txt,sha256=aYLB_1WODsqNTsTFWcKP-BN0KCTKcV-HZJ4zlHkCFw8,6
|
20
|
+
ezKit-1.9.9.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|