lazysdk 0.1.87__py3-none-any.whl → 0.1.89__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.
- lazysdk/lazyfile.py +23 -51
- lazysdk/lazytext.py +22 -0
- lazysdk/lazytime.py +10 -0
- lazysdk/lazyxml.py +24 -0
- {lazysdk-0.1.87.dist-info → lazysdk-0.1.89.dist-info}/METADATA +3 -1
- {lazysdk-0.1.87.dist-info → lazysdk-0.1.89.dist-info}/RECORD +9 -8
- {lazysdk-0.1.87.dist-info → lazysdk-0.1.89.dist-info}/LICENSE +0 -0
- {lazysdk-0.1.87.dist-info → lazysdk-0.1.89.dist-info}/WHEEL +0 -0
- {lazysdk-0.1.87.dist-info → lazysdk-0.1.89.dist-info}/top_level.txt +0 -0
lazysdk/lazyfile.py
CHANGED
@@ -21,7 +21,8 @@ import xlrd
|
|
21
21
|
import json
|
22
22
|
import sys
|
23
23
|
import os
|
24
|
-
import zipfile
|
24
|
+
# import zipfile
|
25
|
+
from rich.progress import Progress
|
25
26
|
from requests import exceptions
|
26
27
|
|
27
28
|
headers_default = {"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:68.0) Gecko/20100101 Firefox/68.0"}
|
@@ -183,9 +184,9 @@ def download(
|
|
183
184
|
temp_size = 0 # 已经下载文件大小
|
184
185
|
else:
|
185
186
|
temp_size = range_start + 0 # 已经下载文件大小
|
186
|
-
chunk_size = 1024 # 分割文件大小,字节B
|
187
|
+
chunk_size = 1024 * 1024 # 分割文件大小,字节B
|
187
188
|
total_size = int(total_length) # 文件总大小
|
188
|
-
total_size_mb = round(total_size / (1024 * 1024), 2) # 换算到MB的文件大小
|
189
|
+
# total_size_mb = round(total_size / (1024 * 1024), 2) # 换算到MB的文件大小
|
189
190
|
# 添加文件大小控制,跳过下载超大文件
|
190
191
|
if size_limit is None:
|
191
192
|
pass
|
@@ -195,7 +196,6 @@ def download(
|
|
195
196
|
else:
|
196
197
|
pass
|
197
198
|
|
198
|
-
time_start = time.time() # 获取下载开始时间
|
199
199
|
is_finish = False
|
200
200
|
|
201
201
|
if overwrite and os.path.exists(path_local):
|
@@ -216,54 +216,26 @@ def download(
|
|
216
216
|
pass
|
217
217
|
|
218
218
|
with open(path_local, "ab") as f: # wb新建文件,a追加
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
is_finish = True
|
230
|
-
else:
|
231
|
-
is_finish = False
|
232
|
-
break
|
233
|
-
else:
|
234
|
-
temp_size += len(chunk)
|
235
|
-
f.write(chunk)
|
236
|
-
f.flush()
|
237
|
-
done = int(50 * temp_size / total_size)
|
238
|
-
if total_speed == 0 or time_spend_total == 0:
|
239
|
-
time_left = 0
|
240
|
-
else:
|
241
|
-
time_left = (total_size - temp_size) / total_speed / 1024 / 1024
|
242
|
-
show_dict = {
|
243
|
-
'finish_mark': '█' * done,
|
244
|
-
'not_finish_mark': ' ' * (50 - done),
|
245
|
-
'total_size': total_size_mb, # 换算到M
|
246
|
-
'total_percent': round(100 * temp_size / total_size, 4),
|
247
|
-
'total_speed': total_speed,
|
248
|
-
'finish_size': round(temp_size / (1024 * 1024), 2),
|
249
|
-
'time_spend_total': int(time_spend_total),
|
250
|
-
'time_left': int(time_left)
|
251
|
-
}
|
252
|
-
show_msg = "\r[%(finish_mark)s%(not_finish_mark)s] " \
|
253
|
-
"总大小:%(total_size)sMB " \
|
254
|
-
"总进度:%(total_percent)s%% " \
|
255
|
-
"平均速度:%(total_speed)sMB/s " \
|
256
|
-
"已下载:%(finish_size)sMB " \
|
257
|
-
"已耗时 %(time_spend_total)s 秒 " \
|
258
|
-
"预计剩余 %(time_left)s 秒" % show_dict
|
259
|
-
sys.stdout.write(show_msg)
|
260
|
-
sys.stdout.flush()
|
261
|
-
if temp_size >= total_size:
|
262
|
-
is_finish = True
|
219
|
+
with Progress() as progress:
|
220
|
+
task = progress.add_task(description="[red]Downloading...", total=total_size)
|
221
|
+
for chunk in response.iter_content(chunk_size=chunk_size):
|
222
|
+
try:
|
223
|
+
if not chunk:
|
224
|
+
if temp_size >= total_size:
|
225
|
+
is_finish = True
|
226
|
+
else:
|
227
|
+
is_finish = False
|
228
|
+
break
|
263
229
|
else:
|
264
|
-
|
265
|
-
|
266
|
-
|
230
|
+
f.write(chunk)
|
231
|
+
f.flush()
|
232
|
+
progress.update(task, advance=chunk_size)
|
233
|
+
if temp_size >= total_size:
|
234
|
+
is_finish = True
|
235
|
+
else:
|
236
|
+
is_finish = False
|
237
|
+
except:
|
238
|
+
showlog.error('')
|
267
239
|
print("\n ==> 文件已全部下载完成,保存位置:", path_local)
|
268
240
|
res_dict = {
|
269
241
|
'file_dir': path_local,
|
lazysdk/lazytext.py
CHANGED
@@ -75,3 +75,25 @@ def file_name_format(text):
|
|
75
75
|
"""
|
76
76
|
text_new = re.sub(r'[\\/:*?"<>|\r\n]+', "_", text) # 规避windows非法字符
|
77
77
|
return text_new
|
78
|
+
|
79
|
+
|
80
|
+
def name_head_list(
|
81
|
+
your_name: str
|
82
|
+
):
|
83
|
+
"""
|
84
|
+
获取姓名的首字母缩写的所有可能列表
|
85
|
+
:param your_name:
|
86
|
+
:return:
|
87
|
+
"""
|
88
|
+
from xpinyin import Pinyin
|
89
|
+
p = Pinyin()
|
90
|
+
name_pinyins = p.get_pinyins(your_name)
|
91
|
+
name_heads = list()
|
92
|
+
for each_name_pinyin in name_pinyins:
|
93
|
+
name_pinyin_split = each_name_pinyin.split('-')
|
94
|
+
name_head = ""
|
95
|
+
for each_split in name_pinyin_split:
|
96
|
+
each_split_0 = each_split[0]
|
97
|
+
name_head += each_split_0
|
98
|
+
name_heads.append(name_head)
|
99
|
+
return name_heads
|
lazysdk/lazytime.py
CHANGED
@@ -975,3 +975,13 @@ def get_recent_days_date(
|
|
975
975
|
start_date=get_date_string(days=num_start),
|
976
976
|
end_date=get_date_string(days=num_end)
|
977
977
|
)
|
978
|
+
|
979
|
+
|
980
|
+
def network_timestamp():
|
981
|
+
"""
|
982
|
+
获取网络时间,精确到毫秒
|
983
|
+
"""
|
984
|
+
url = 'https://api.m.taobao.com/rest/api3.do?api=mtop.common.getTimestamp' # 淘宝网络取时
|
985
|
+
res = requests.get(url=url)
|
986
|
+
net_t = res.json()['data']['t'] # 精确到毫秒的时间戳
|
987
|
+
return int(net_t)
|
lazysdk/lazyxml.py
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
from xml.etree import ElementTree
|
2
|
+
import re
|
3
|
+
|
4
|
+
|
5
|
+
def xml2dict(xml_str: str):
|
6
|
+
"""
|
7
|
+
XML代码转dict
|
8
|
+
在格式化之前,先抽取出xml标签内的内容,防止有干扰
|
9
|
+
参考:https://docs.python.org/zh-cn/3.8/library/xml.etree.elementtree.html
|
10
|
+
https://blog.csdn.net/qdPython/article/details/115520713
|
11
|
+
:param xml_str:
|
12
|
+
:return:
|
13
|
+
"""
|
14
|
+
res_dict = dict()
|
15
|
+
xml_str_res = re.findall(r'<xml>(.*?)</xml>', xml_str, re.S)
|
16
|
+
if xml_str_res:
|
17
|
+
xml_str_process = f"<xml>{xml_str_res[0]}</xml>"
|
18
|
+
root = ElementTree.fromstring(xml_str_process)
|
19
|
+
for child in root:
|
20
|
+
# print(child.tag, child.attrib, child.text)
|
21
|
+
res_dict[child.tag] = child.text
|
22
|
+
return res_dict
|
23
|
+
else:
|
24
|
+
return res_dict
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: lazysdk
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.89
|
4
4
|
Summary: 基于Python的懒人包
|
5
5
|
Home-page: https://gitee.com/ZeroSeeker/lazysdk
|
6
6
|
Author: ZeroSeeker
|
@@ -22,6 +22,8 @@ Requires-Dist: pycryptodome ==3.10.1
|
|
22
22
|
Requires-Dist: filetype ==1.2.0
|
23
23
|
Requires-Dist: netifaces ==0.11.0
|
24
24
|
Requires-Dist: user-agents ==2.2.0
|
25
|
+
Requires-Dist: rich >=13.5.2
|
26
|
+
Requires-Dist: urllib3 ==1.23
|
25
27
|
|
26
28
|
# lazysdk
|
27
29
|

|
@@ -8,7 +8,7 @@ lazysdk/lazydecode.py,sha256=z3no94VDhxVxJCPQFwKxKTxz8v9Eikjk18TZWDttN6A,414
|
|
8
8
|
lazysdk/lazydict.py,sha256=LOUUpsPlewgZEX3jb90BEA_C4haOSrXods5B1g1nt_k,8883
|
9
9
|
lazysdk/lazyenv.py,sha256=P6HjO9cbBPzHD_Vs-Ww_GThDq-h9Wn31VSiu9OzTNWI,3024
|
10
10
|
lazysdk/lazyexcel.py,sha256=adZTtQYuVZ2u5jMSRBJlKluGVdN7oHxJsLpxawV1ros,15835
|
11
|
-
lazysdk/lazyfile.py,sha256=
|
11
|
+
lazysdk/lazyfile.py,sha256=SoOLCongBAx93QYBxU5jMc5F37e9BM7R9fzaB4LC1Cw,20263
|
12
12
|
lazysdk/lazyflask.py,sha256=VUhJqtNz_evVyGOS40FKkkQWWrqGEUZ26cv1RQxS388,727
|
13
13
|
lazysdk/lazyhtml.py,sha256=vTtiLPoAhWMzXsDBFsF0DoFSsKbfmuEPjPMOZI_n6ag,1867
|
14
14
|
lazysdk/lazyid.py,sha256=tpiIjITLvYRVs9JASZZM2hvA-ngzoVFwGnepAzMhWT8,1287
|
@@ -23,15 +23,16 @@ lazysdk/lazyproxies.py,sha256=bljLKkP3WksZ6jOHhjS5-jSHdUBRH6gx-BxEZTPJeXc,546
|
|
23
23
|
lazysdk/lazyrandom.py,sha256=XZ8hTcNvc68FAI-BfaIt7QpCmzZ7m4RGDrfpy_U7zTw,1420
|
24
24
|
lazysdk/lazyredis.py,sha256=78jM_tXNgUKULcp08CQEHmfAlzwlWuOsl6SuLwoLDdM,37918
|
25
25
|
lazysdk/lazyrequests.py,sha256=qOUNkFhIThHNLALDTmOqPjKgMse5BVD-Kf9kheadMAY,3750
|
26
|
-
lazysdk/lazytext.py,sha256=
|
27
|
-
lazysdk/lazytime.py,sha256=
|
26
|
+
lazysdk/lazytext.py,sha256=uyfXscNNqbozLrHm-mmIzf-CGG158qBsN3MJhimWROQ,2627
|
27
|
+
lazysdk/lazytime.py,sha256=3GHfck89GNg556gYCoCd5NpntybBU848gJ1Udv1jikk,26530
|
28
28
|
lazysdk/lazyua.py,sha256=IqLmqGDECdJa3Wcr8h6sTxMErJZlCTM3Jk7IWm90UzI,4827
|
29
29
|
lazysdk/lazyurl.py,sha256=N89QLK2A6vXr9gqp-9vnk9RXv_fOjw171lVl9eEoxtE,1550
|
30
30
|
lazysdk/lazywebhook.py,sha256=HwJIZ5j3wUpnEfPkFY-Xq9T_9xdhCJ71dYsWNX22_3Y,8386
|
31
31
|
lazysdk/lazywifi.py,sha256=FOvLPTcb6BQE6D8kjfB0TLpfgGxw8jqC3vZbTs6LbD4,716
|
32
|
+
lazysdk/lazyxml.py,sha256=PLAcDWjpu2GMJPsV9dHOv716CVmflQee7Aan-hqGxL8,770
|
32
33
|
lazysdk/showdata.py,sha256=957JMXq7qfJ4ELpA3nBJwkyEUn6mRwtVXVBGYfZaCgg,1683
|
33
|
-
lazysdk-0.1.
|
34
|
-
lazysdk-0.1.
|
35
|
-
lazysdk-0.1.
|
36
|
-
lazysdk-0.1.
|
37
|
-
lazysdk-0.1.
|
34
|
+
lazysdk-0.1.89.dist-info/LICENSE,sha256=OC5E4ENUG6B4dGEVGwUpdsD-D9SZsCVC92NAgaqvE-c,1088
|
35
|
+
lazysdk-0.1.89.dist-info/METADATA,sha256=aQbBXRfd_jT3QhyqJmOD2pjLgJhkbBoAYIWWjRC1xyU,1912
|
36
|
+
lazysdk-0.1.89.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
37
|
+
lazysdk-0.1.89.dist-info/top_level.txt,sha256=--bGS42ZHUhVeO83y1wfvKFg6OjkTLxQ4V4riqPQljY,8
|
38
|
+
lazysdk-0.1.89.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|