From 3c44bdbe1ca1f55e168c96b2c439d704f4b2502b Mon Sep 17 00:00:00 2001 From: vision Date: Sun, 3 Sep 2023 15:10:05 +0800 Subject: [PATCH 1/4] Update requirements-optional.txt --- requirements-optional.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-optional.txt b/requirements-optional.txt index 17c4c1f..f9f4a9e 100644 --- a/requirements-optional.txt +++ b/requirements-optional.txt @@ -21,9 +21,9 @@ wechaty_puppet>=0.4.23 # wechatmp wechatcom web.py wechatpy +pilk # chatgpt-tool-hub plugin ---extra-index-url https://pypi.python.org/simple chatgpt_tool_hub==0.4.6 # xunfei spark From 5cc8b56a7c1b76e5bd9aaa7bbbcfee255341a857 Mon Sep 17 00:00:00 2001 From: vision Date: Sun, 3 Sep 2023 16:29:19 +0800 Subject: [PATCH 2/4] Optimize image download and storage logic - Implement new compression logic for files larger than 10MB to improve storage efficiency. - Switch from JPEG to PNG to enhance image quality and compatibility. --- channel/wework/wework_channel.py | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/channel/wework/wework_channel.py b/channel/wework/wework_channel.py index 5182789..87a0016 100644 --- a/channel/wework/wework_channel.py +++ b/channel/wework/wework_channel.py @@ -16,6 +16,7 @@ from channel.wework.wework_message import WeworkMessage from common.singleton import singleton from common.log import logger from common.time_check import time_checker +from common.utils import compress_imgfile, fsize from config import conf from channel.wework.run import wework from channel.wework import run @@ -38,12 +39,25 @@ def download_and_compress_image(url, filename, quality=30): os.makedirs(directory) # 下载图片 - response = requests.get(url) - image = Image.open(io.BytesIO(response.content)) - - # 压缩图片 - image_path = os.path.join(directory, f"{filename}.jpg") - image.save(image_path, "JPEG", quality=quality) + pic_res = requests.get(url, stream=True) + image_storage = io.BytesIO() + for block in pic_res.iter_content(1024): + image_storage.write(block) + + # 检查图片大小并可能进行压缩 + sz = fsize(image_storage) + if sz >= 10 * 1024 * 1024: # 如果图片大于 10 MB + logger.info("[wework] image too large, ready to compress, sz={}".format(sz)) + image_storage = compress_imgfile(image_storage, 10 * 1024 * 1024 - 1) + logger.info("[wework] image compressed, sz={}".format(fsize(image_storage))) + + # 将内存缓冲区的指针重置到起始位置 + image_storage.seek(0) + + # 读取并保存图片 + image = Image.open(image_storage) + image_path = os.path.join(directory, f"{filename}.png") + image.save(image_path, "png") return image_path From 139295fe0d91702a78252bcb2ef3d685578961ba Mon Sep 17 00:00:00 2001 From: vision Date: Sun, 3 Sep 2023 16:47:25 +0800 Subject: [PATCH 3/4] Update requirements-optional.txt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 增加企微个人号channel所需依赖 --- requirements-optional.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/requirements-optional.txt b/requirements-optional.txt index f9f4a9e..a9028b7 100644 --- a/requirements-optional.txt +++ b/requirements-optional.txt @@ -21,7 +21,10 @@ wechaty_puppet>=0.4.23 # wechatmp wechatcom web.py wechatpy + +# wework pilk +natchat # chatgpt-tool-hub plugin chatgpt_tool_hub==0.4.6 From 96542b532e2844c611bb4ac36619fa990c9fa901 Mon Sep 17 00:00:00 2001 From: vision Date: Sun, 3 Sep 2023 17:14:28 +0800 Subject: [PATCH 4/4] Update requirements-optional.txt --- requirements-optional.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements-optional.txt b/requirements-optional.txt index a9028b7..dadd5df 100644 --- a/requirements-optional.txt +++ b/requirements-optional.txt @@ -24,7 +24,7 @@ wechatpy # wework pilk -natchat +ntwork # chatgpt-tool-hub plugin chatgpt_tool_hub==0.4.6