From 53c861698b1b220579497a61eba4da0eed2fa02c Mon Sep 17 00:00:00 2001 From: Redume Date: Sat, 28 Oct 2023 22:02:29 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=B0=D0=BC=D1=8B=20=D0=B8=20=D0=B3?= =?UTF-8?q?=D0=BE=D1=81=D0=BF=D0=BE=D0=B4=D0=B0,=20=D1=83=20=D0=BD=D0=B0?= =?UTF-8?q?=D1=81=2010=20=D0=BD=D0=BE=D0=B2=D1=8B=D1=85=20=D0=B1=D0=B0?= =?UTF-8?q?=D0=B3=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 03bfb9c..cf5ff27 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,7 @@ import logging import string from typing import Any, Dict, List, Optional +import aiohttp.client_exceptions import requests from pydantic.v1 import BaseSettings @@ -125,14 +126,16 @@ class CurrencyConverter: log.debug(data) # If the currency does not exist - error = data.get('to')[0].get('quotecurrency') - if error is None: + error = data.get('to') + + if len(error) == 0: return False # Otherwise conv: Dict[str, str] = data.get('to')[0] conv_amount = conv.get('mid') - if conv_amount is None: + + if not conv_amount: raise RuntimeError('Ошибка при конвертации через DDG') self.conv_amount = float(conv_amount) @@ -215,6 +218,9 @@ async def currency(inline_query: types.InlineQuery) -> None: f'{conv.conv_amount} {conv.conv_currency}' ) + except aiohttp.client_exceptions.ClientError: + result = "Рейт-лимит от api telegram, попробуйте позже" + except Exception as ex: result = f'{type(ex).__name__}: {ex}'