From 2e918381ab7197e13aa2321ecb2a2bec61cb4f4b Mon Sep 17 00:00:00 2001 From: Ali Askari Date: Sat, 28 Dec 2024 20:43:10 +0330 Subject: [PATCH] select main currency --- main.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 0dd9825..1d969b1 100644 --- a/main.py +++ b/main.py @@ -48,19 +48,22 @@ def format_data_for_telegram(data): # Add more currencies and their Persian names as needed } + currencies_to_send = ['usd', 'eur', 'gbp', 'chf', 'jpy', 'try', 'cny', 'rub', 'aed', 'emami1', 'azadi1g', 'azadi1', 'azadi12', 'azadi14', 'mithqal', 'gol18', 'ounce', 'bitcoin'] + formatted_lines = [] for key, values in data.items(): - flag = currency_flags.get(key.lower(), '') - name_persian = currency_names_persian.get(key.lower(), key.upper()) - - if key.lower() not in ['bitcoin', 'ounce']: - sell_price = f"{int(values['sell']):,} تومن" - buy_price = f"{int(values['buy']):,} تومن" - else: - sell_price = f"{values['sell']} دلار" - buy_price = f"{values['buy']} دلار" - - formatted_lines.append(f"{flag} • {name_persian}: \n - فروش: {sell_price} \n - خرید: {buy_price}") + if key.lower() in currencies_to_send: + flag = currency_flags.get(key.lower(), '') + name_persian = currency_names_persian.get(key.lower(), key.upper()) + + if key.lower() not in ['bitcoin', 'ounce']: + sell_price = f"{int(values['sell']):,} تومن" + buy_price = f"{int(values['buy']):,} تومن" + else: + sell_price = f"{values['sell']} دلار" + buy_price = f"{values['buy']} دلار" + + formatted_lines.append(f"{flag} • {name_persian}: \n - فروش: {sell_price} \n - خرید: {buy_price}") formatted_message = "\n\n".join(formatted_lines) @@ -71,7 +74,6 @@ def format_data_for_telegram(data): return formatted_message - def send_to_telegram(message): telegram_url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage" payload = {"chat_id": TELEGRAM_CHAT_ID, "text": f"\u200F{message}", "parse_mode": "Markdown"}