From 55d0b8ae1e4fd99f1e91e6b897b5a2d3e141793c Mon Sep 17 00:00:00 2001 From: Sergey Date: Thu, 3 Dec 2020 19:27:12 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D1=80=D0=B0=D0=B7?= =?UTF-8?q?=D0=BC=D0=B5=D1=80=D0=B0=20=D0=BA=D0=B0=D1=80=D1=82=D0=B8=D0=BD?= =?UTF-8?q?=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Больше не надеемся на позицию, а считаем ширину и высоту самостоятельно --- vk_messages.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vk_messages.py b/vk_messages.py index 5963827..24ac06e 100644 --- a/vk_messages.py +++ b/vk_messages.py @@ -911,10 +911,14 @@ def form_audio_title(data: dict, delimer=' '): return result +def search_max_vk_photo_size(sizes: list) -> dict: + return list(sorted(sizes, key=lambda x: (int(x.get('width', 0)), int(x.get('height', 0))), reverse=True))[0] + + async def process_attachment(attachment, token=None, vk_msg_url=None): atype = attachment.get('type') if atype == 'photo': - photo_url = attachment[atype]['sizes'][-1]['url'] + photo_url = search_max_vk_photo_size(attachment[atype]['sizes'])['url'] return {'content': photo_url, 'type': 'photo'} elif atype == 'audio_message':