From cf0da8f220f4952301d14be0eefc6e58634ea575 Mon Sep 17 00:00:00 2001 From: Redume Date: Tue, 29 Oct 2024 18:14:28 +0300 Subject: [PATCH] feat: Deleted the conversion via aliases --- currency.json | 8 -------- main.py | 26 +++++++------------------- 2 files changed, 7 insertions(+), 27 deletions(-) delete mode 100644 currency.json diff --git a/currency.json b/currency.json deleted file mode 100644 index e340229..0000000 --- a/currency.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "RUB": ["руб", "рубли", "рубля", "рублей", "рубль", "российский рубль", "rub", "rouble", "roubles", "russian rouble"], - "USD": ["доллары", "доллар", "доллара", "долларах", "долларов", "зеленых", "бакса", "баксов", "usd", "dollar", "dollars"], - "UAH": ["гривны", "гривен", "гривен", "hryvnia"], - "EUR": ["евро", "eur", "euro", "euros"], - "KZT": ["тенге", "казахстанский тенге", "kazakhstani tenge", "tenge"], - "TRY": ["турецкая лира", "турецких лир", "try", "tl", "Turkish lira", "lira"] -} \ No newline at end of file diff --git a/main.py b/main.py index 75f264a..dc3346d 100644 --- a/main.py +++ b/main.py @@ -16,10 +16,9 @@ dp = Dispatcher() @dp.message() @dp.inline_query() async def currency(query: types.Message | types.InlineQuery) -> None: - global result, from_currency_alias, conv_currency_alias + global result, from_currency, conv_currency try: - currency_json = json.load(open('currency.json', 'r', encoding='utf-8')) text = query.query if isinstance(query, types.InlineQuery) else query.text args = text.split() result_id = hashlib.md5(text.encode()).hexdigest() @@ -39,15 +38,15 @@ async def currency(query: types.Message | types.InlineQuery) -> None: query) if len(args) == 4: conv.amount = float(args[0]) - from_currency_alias = args[1].lower() - conv_currency_alias = args[3].lower() + from_currency = args[1].lower() + conv_currency = args[3].lower() elif len(args) == 3: conv.amount = float(args[0]) - from_currency_alias = args[1].lower() - conv_currency_alias = args[2].lower() + from_currency = args[1].lower() + conv_currency = args[2].lower() elif len(args) == 2: - from_currency_alias = args[0].lower() - conv_currency_alias = args[1].lower() + from_currency = args[0].lower() + conv_currency = args[1].lower() else: try: if query.chat.type in ['supergroup', 'group']: @@ -57,17 +56,6 @@ async def currency(query: types.Message | types.InlineQuery) -> None: return await reply(result_id, 'The source and target currency could not be determined.', None, query) - from_currency, conv_currency = None, None - - for currency_code, aliases in currency_json.items(): - if from_currency_alias in aliases: - from_currency = currency_code - if conv_currency_alias in aliases: - conv_currency = currency_code - - if from_currency and conv_currency: - break - if not from_currency or not conv_currency: return await reply(result_id, 'The currency exchange rate could not be found.',