From 547132d5d6d240adc9dbb9404cd07d721ca0cb0a Mon Sep 17 00:00:00 2001 From: bakatrouble Date: Wed, 22 Mar 2023 19:28:33 +0300 Subject: [PATCH] log send exception --- main.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/main.py b/main.py index bacec7f..e941f7d 100644 --- a/main.py +++ b/main.py @@ -5,7 +5,7 @@ import os import redis.asyncio as aioredis from aiogram import Bot, Dispatcher from aiogram.types import Message -from aiogram.utils import executor +from aiogram.utils import executor, exceptions import dotenv from e621 import E621 @@ -38,19 +38,22 @@ async def check_updates(): f'Character: {" ".join(post.tags.character)}\n\n' \ f'https://e621.net/posts/{post.id}' if post.file.url: - logging.warning(post.file.url) - if post.file.ext == 'webm': - await bot.send_video(int(os.environ['SEND_CHAT']), - post.file.url, - width=post.file.width, - height=post.file.height, - thumb=post.preview.url, - caption=caption) - else: - await bot.send_photo(int(os.environ['SEND_CHAT']), - post.file.url, - caption=caption) - await redis.sadd('e621:sent', post.id) + try: + logging.warning(post.file.url) + if post.file.ext == 'webm': + await bot.send_video(int(os.environ['SEND_CHAT']), + post.file.url, + width=post.file.width, + height=post.file.height, + thumb=post.preview.url, + caption=caption) + else: + await bot.send_photo(int(os.environ['SEND_CHAT']), + post.file.url, + caption=caption) + await redis.sadd('e621:sent', post.id) + except exceptions.TelegramAPIError as e: + logging.exception(e) @dp.message_handler(commands=['add'])