From c6bcb5900562074e75c0d2bd7f0aeaba804b4823 Mon Sep 17 00:00:00 2001 From: msramalho <19508417+msramalho@users.noreply.github.com> Date: Wed, 15 Jun 2022 23:36:10 +0200 Subject: [PATCH] improvement for albums --- archivers/vk_archiver.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/archivers/vk_archiver.py b/archivers/vk_archiver.py index ee43e8e..e48e9ef 100644 --- a/archivers/vk_archiver.py +++ b/archivers/vk_archiver.py @@ -69,7 +69,18 @@ class VkArchiver(Archiver): req = requests.get("https://api.vk.com/method/wall.getById", headers) res = req.json()["response"] wall = res["items"][0] - img_urls = [p[p["type"]]["sizes"][-1]["url"] for p in wall["attachments"]] if "attachments" in wall else [] + img_urls = [] + if "attachments" in wall: + for a in wall["attachments"]: + attachment = a[a["type"]] + if "thumb" in attachment: + attachment = attachment["thumb"] + if "sizes" in attachment: + try: img_urls.append(attachment["sizes"][-1]["url"]) + except Exception as e: + logger.warning(f"could not get image from attachment: {e}") + + title = wall["text"][:200] # more on the page time = dateparser.parse(str(wall["date"]), settings={"RETURN_AS_TIMEZONE_AWARE": True, "TO_TIMEZONE": "UTC"})