From 20c79b5bc02e78f2fc12d80c6bd34fe167ca8f17 Mon Sep 17 00:00:00 2001 From: dongchangxi <458593490@qq.com> Date: Fri, 3 Jan 2025 16:53:46 +0800 Subject: [PATCH] 1 --- libs/libs.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/libs/libs.py b/libs/libs.py index d8950b1..8bcbb6c 100644 --- a/libs/libs.py +++ b/libs/libs.py @@ -378,4 +378,62 @@ def down_obj_from_oss_auto(pid,action,pathStr): print(filename) localfile = os.path.join(pathStr, filename) - config.oss_bucket.get_object_to_file(file.key, localfile) \ No newline at end of file + config.oss_bucket.get_object_to_file(file.key, localfile) + + + +def down_from_oss_photo2(oss_client, workdir, pid, per=100,photoPath=""): + start_time = time.time() + path = os.path.join(workdir, pid) + if os.path.exists(path): + print(f"Directory {path} already exists, skip") + return + # os.makedirs(os.path.join(path, 'photo1')) + os.makedirs(os.path.join(path, 'photo2')) + + psid = getPSid(pid) + # 根据前缀获取文件列表 + prefix = f'photos/{pid}/photo2' + filelist = oss2.ObjectIteratorV2(oss_client, prefix=prefix) + for file in tqdm(filelist): + filename = file.key.split('/')[-1] + localfile = "" + # print('正在下载:', file.key) + if photoPath == "": + if filename.endswith('_1.jpg'): + localfile = os.path.join(path, 'photo1', filename) + else: + localfile = os.path.join(path, 'photo2', filename) + else: + if photoPath=="1": + if filename.endswith('_1.jpg'): + localfile = os.path.join(path, 'photo1', filename) + else: + if filename.endswith('_8.jpg'): + localfile = os.path.join(path, 'photo2', filename) + if localfile == "": + continue + style = f'image/resize,p_{per}' + if per == 100: + oss_client.get_object_to_file(file.key, localfile) + else: + oss_client.get_object_to_file(file.key, localfile, process=style) + + #判断localfile 是否有包含 photo2 + + + #遍历处理photo2的数数据 + # if str(psid) == "96" or str(pid) == "118994": + # path = os.path.join(workdir, pid, 'photo2') + # files = [] + # for fileName in os.listdir(path): + # if ".jpg" in fileName: + # files.append(path+"\\"+fileName) + # beginTime = time.time() + # with ThreadPoolExecutor(max_workers=6) as executor: + # executor.map(process_image, files) + + # print(f'{localfile}灰度处理费时{diff_time(beginTime)}') + + + print(f'{time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())} pid: {pid} 图片下载完成, 共费时{diff_time(start_time)}') \ No newline at end of file