mdbq 3.7.0__py3-none-any.whl → 3.7.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.
mdbq/bdup/bdup.py
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
import os
|
3
3
|
import platform
|
4
4
|
import subprocess
|
5
|
+
from concurrent.futures import ThreadPoolExecutor
|
5
6
|
from bypy import ByPy
|
6
7
|
|
7
8
|
|
@@ -12,13 +13,15 @@ class BaiDu:
|
|
12
13
|
def __init__(self):
|
13
14
|
self.local_path = None
|
14
15
|
self.remote_path = None
|
15
|
-
self.skip = [
|
16
|
-
self.delete_remote_files = [
|
16
|
+
self.skip:list = []
|
17
|
+
self.delete_remote_files:list = []
|
17
18
|
self.bp = ByPy()
|
19
|
+
self.count = 0
|
20
|
+
self.total = 0
|
18
21
|
|
19
22
|
def upload_dir(self, local_path, remote_path):
|
20
23
|
"""
|
21
|
-
|
24
|
+
上传整个文件夹,执行完后删除指定文件, 指定 self.delete_remote_files
|
22
25
|
如果通过调用命令行终端运行, 《云端路径!!》必须使用linux格式,不要使用反斜杆,否则在windows系统里面会上传失败
|
23
26
|
"""
|
24
27
|
self.local_path = local_path
|
@@ -37,38 +40,59 @@ class BaiDu:
|
|
37
40
|
print(e)
|
38
41
|
self.delete_files() # 最好是在内部执行删除, 避免路径异常
|
39
42
|
|
40
|
-
def upload_file(self, local_path, remote_path):
|
43
|
+
def upload_file(self, local_path, remote_path, processes=False):
|
41
44
|
"""
|
42
|
-
|
45
|
+
上传文件夹,按单个文件上传,可以跳过指定文件/文件夹, 指定 self.skip
|
43
46
|
《云端路径!!》必须使用linux格式
|
44
47
|
"""
|
48
|
+
if not isinstance(self.skip, list):
|
49
|
+
raise TypeError('skip must be a list')
|
50
|
+
self.skip += ['.DS_Store', '.localized', 'desktop.ini', '$RECYCLE.BIN', 'Icon']
|
45
51
|
self.local_path = local_path
|
46
52
|
self.remote_path = remote_path.replace('\\', '/')
|
47
53
|
if not os.path.exists(self.local_path):
|
48
54
|
print(f'{self.local_path}: 本地目录不存在,没有什么可传的')
|
49
55
|
return
|
50
56
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
+
local_files = os.listdir(self.local_path)
|
58
|
+
|
59
|
+
local_file_list = []
|
60
|
+
for file in local_files:
|
61
|
+
if file in self.skip: # 跳过指定文件/文件夹
|
62
|
+
continue
|
63
|
+
local_p = os.path.join(self.local_path, file)
|
64
|
+
if os.path.isfile(local_p):
|
57
65
|
rt_path = os.path.join(self.remote_path, file).replace('\\', '/')
|
58
|
-
|
59
|
-
|
60
|
-
elif os.path.isdir(
|
61
|
-
for root, dirs, files in os.walk(
|
66
|
+
self.total += 1
|
67
|
+
local_file_list.append({local_p: rt_path})
|
68
|
+
elif os.path.isdir(local_p):
|
69
|
+
for root, dirs, files in os.walk(local_p, topdown=False):
|
62
70
|
for name in files:
|
63
|
-
if name in self.skip:
|
71
|
+
if name in self.skip: # 从子文件夹内跳过指定文件
|
64
72
|
continue
|
65
73
|
lc_path = os.path.join(root, name)
|
66
74
|
rt_path = lc_path.replace(self.local_path, self.remote_path).replace('\\', '/')
|
67
|
-
|
68
|
-
|
75
|
+
self.total += 1
|
76
|
+
local_file_list.append({lc_path: rt_path})
|
77
|
+
if processes:
|
78
|
+
# 不指定 max_workers 参数,默认值是 os.cpu_count() * 5
|
79
|
+
with ThreadPoolExecutor() as executor:
|
80
|
+
executor.map(self.up_one_file, local_file_list)
|
81
|
+
else:
|
82
|
+
for item in local_file_list:
|
83
|
+
self.up_one_file(file_dict=item)
|
84
|
+
|
85
|
+
def up_one_file(self, file_dict:dict):
|
86
|
+
if not isinstance(file_dict, dict):
|
87
|
+
raise TypeError('file_dict must be a dict')
|
88
|
+
for k, v in file_dict.items():
|
89
|
+
self.count += 1
|
90
|
+
print(f'上传: {self.count}/{self.total} {k}')
|
91
|
+
self.bp.upload(localpath=k, remotepath=v) # 上传文件到百度云
|
69
92
|
|
70
93
|
def delete_files(self):
|
71
94
|
""" 移除云端文件,位于 self.remote_path 文件夹下的子文件 """
|
95
|
+
self.delete_remote_files += ['.DS_Store', '.localized', 'desktop.ini', '$RECYCLE.BIN', 'Icon']
|
72
96
|
for delete_file in self.delete_remote_files:
|
73
97
|
self.bp.remove(remotepath=f'{self.remote_path.replace('\\', '/')}/{delete_file}') # 移除文件
|
74
98
|
|
@@ -83,9 +107,5 @@ class BaiDu:
|
|
83
107
|
|
84
108
|
|
85
109
|
if __name__ == '__main__':
|
86
|
-
|
87
|
-
|
88
|
-
upload_path = f'windows/{str(datetime.date.today().strftime("%Y-%m"))}/{str(datetime.date.today())}'
|
89
|
-
b = BaiDu()
|
90
|
-
# b.upload_dir(local_path='/Users/xigua/Downloads', remote_path=upload_path)
|
91
|
-
b.download_dir(local_path='/Users/xigua/Downloads', remote_path=upload_path)
|
110
|
+
bp = ByPy()
|
111
|
+
bp.list()
|
@@ -6,7 +6,7 @@ mdbq/aggregation/datashow_bak.py,sha256=1AYSIDkdUx-4as1Ax2rPj0cExM9d-qFMrFYLAaPH
|
|
6
6
|
mdbq/aggregation/optimize_data.py,sha256=foZGLDGJRhM2qOr2mTvB3InDFId7r4KBXrJfB3-xq1k,2639
|
7
7
|
mdbq/aggregation/query_data.py,sha256=AiG0W9Rum_hKCTPNB-nuA5ehpnVW12byLA7uwzOmO6Q,168639
|
8
8
|
mdbq/bdup/__init__.py,sha256=AkhsGk81SkG1c8FqDH5tRq-8MZmFobVbN60DTyukYTY,28
|
9
|
-
mdbq/bdup/bdup.py,sha256=
|
9
|
+
mdbq/bdup/bdup.py,sha256=hJs815hGFwm_X5bP2i9XugG2w2ZY_F0n3-Q0hVpIPPw,4892
|
10
10
|
mdbq/config/__init__.py,sha256=jso1oHcy6cJEfa7udS_9uO5X6kZLoPBF8l3wCYmr5dM,18
|
11
11
|
mdbq/config/default.py,sha256=3IGc4aVuoL6sZh7xkM0GUXwHJD3-HCfYTnb1Q5ZL1UM,4976
|
12
12
|
mdbq/config/myconfig.py,sha256=Akt-7KqSUBdoHQa4_Mw6YC4pA75219d-21iDO30iaD8,894
|
@@ -36,7 +36,7 @@ mdbq/redis/__init__.py,sha256=YtgBlVSMDphtpwYX248wGge1x-Ex_mMufz4-8W0XRmA,12
|
|
36
36
|
mdbq/redis/getredis.py,sha256=oyFwE-8c6uErSGYNIO0z2ng93mH0zstRLD86MWqF6M8,25636
|
37
37
|
mdbq/spider/__init__.py,sha256=RBMFXGy_jd1HXZhngB2T2XTvJqki8P_Fr-pBcwijnew,18
|
38
38
|
mdbq/spider/aikucun.py,sha256=1gAEwCUmhCSpOSRPD2EEcbH3bFGn4sUQnQUAsJb5-qM,19391
|
39
|
-
mdbq-3.7.
|
40
|
-
mdbq-3.7.
|
41
|
-
mdbq-3.7.
|
42
|
-
mdbq-3.7.
|
39
|
+
mdbq-3.7.1.dist-info/METADATA,sha256=uHL1bLpTvZHQVsfp6WHV5Ceog2VTGOfZhcbj0-WW16I,243
|
40
|
+
mdbq-3.7.1.dist-info/WHEEL,sha256=eOLhNAGa2EW3wWl_TU484h7q1UNgy0JXjjoqKoxAAQc,92
|
41
|
+
mdbq-3.7.1.dist-info/top_level.txt,sha256=2FQ-uLnCSB-OwFiWntzmwosW3X2Xqsg0ewh1axsaylA,5
|
42
|
+
mdbq-3.7.1.dist-info/RECORD,,
|
File without changes
|