Код:
elif message.text == ' Конвертер валют':
await message.answer('Выберите вашу валюту', reply_markup=currency_converterkbd)
await Finance_states.to_convert.set()
@dptr.message_handler(state=Finance_states.to_convert)
async def answer_for_act_to_small(message: types.Message, state: FSMContext):
can_do = True
await state.update_data(text=message.text)
data = await state.get_data()
global currencies_for_currency_converter
currencies_for_currency_converter[message.chat.id] = data['text']
if currencies_for_currency_converter[message.chat.id] != ' RUB' and currencies_for_currency_converter[message.chat.id] != ' USD' and currencies_for_currency_converter[message.chat.id] != ' EUR' and currencies_for_currency_converter[message.chat.id] != ' GBP' and currencies_for_currency_converter[message.chat.id] != ' JPY' and currencies_for_currency_converter[message.chat.id] != ' AED' and currencies_for_currency_converter[message.chat.id] != ' CHF' and currencies_for_currency_converter[message.chat.id] != ' CNY' and currencies_for_currency_converter[message.chat.id] != ' KZT' and currencies_for_currency_converter[message.chat.id] != ' THB' and currencies_for_currency_converter[message.chat.id] != ' AZN' and currencies_for_currency_converter[message.chat.id] != ' CAD':
if users_id_and_selected_language[message.chat.id] == 'ru':
try:
await state.finish()
except KeyError:
await message.answer('Такой валюты нет в списке, выберите валюту', reply_markup=currency_converterkbd)
await Finance_states.to_convert.set()
elif users_id_and_selected_language[message.chat.id] == 'en':
try:
await state.finish()
except KeyError:
await message.answer("This currency is not on the list, choose currency", reply_markup=currency_converterkbd_en)
await Finance_states.to_convert.set()
can_do = False
if users_id_and_selected_language[message.chat.id] == 'ru':
if currencies_for_currency_converter[message.chat.id] == '↩️ Назад':
try:
await state.finish()
except KeyError:
can_do = False
await mybot.send_message(message.chat.id, 'Выберите раздел ', reply_markup=mainkbd)
if can_do == True:
try:
await state.finish()
except KeyError:
await message.answer('Напишите количество валюты или нажмите ниже', reply_markup=number_of_currency_for_convertingkbd)
await Finance_states.to_convert_main.set()
elif users_id_and_selected_language[message.chat.id] == 'en':
if currencies_for_currency_converter[message.chat.id] == '↩️ Back':
try:
await state.finish()
except KeyError:
can_do = False
await mybot.send_message(message.chat.id, 'Choose section ', reply_markup=mainkbd_en)
if can_do == True:
try:
await state.finish()
except KeyError:
await message.answer('Write the amount of currency or click below', reply_markup=number_of_currency_for_convertingkbd)
await Finance_states.to_convert_main.set()
@dptr.message_handler(state=Finance_states.to_convert_main)
async def answer_for_act_to_small(message: types.Message, state: FSMContext):
await state.update_data(text=message.text)
can_convert = True
data = await state.get_data()
try:
global number_of_currency_for_converting
number_of_currency_for_converting = int(data['text'])
except ValueError:
if users_id_and_selected_language[message.chat.id] == 'ru':
try:
await state.finish()
except KeyError:
await message.answer('Количество должно быть целым числом, напишите или выберите ниже', reply_markup=number_of_currency_for_convertingkbd)
await Finance_states.to_convert_main.set()
elif users_id_and_selected_language[message.chat.id] == 'en':
try:
await state.finish()
except KeyError:
await message.answer('Quantity must be a whole number, write or select below', reply_markup=number_of_currency_for_convertingkbd)
await Finance_states.to_convert_main.set()
can_convert = False
if can_convert == True:
if users_id_and_selected_language[message.chat.id] == 'ru':
await mybot.send_message(message.chat.id, 'Получаем данные...')
elif users_id_and_selected_language[message.chat.id] == 'en':
await mybot.send_message(message.chat.id, 'Getting data...')
if currencies_for_currency_converter[message.chat.id] == ' RUB':
if users_id_and_selected_language[message.chat.id] == 'ru':
await mybot.send_message(
message.chat.id,
f'''
Доллар — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd(), 1)}</b></ins>
Евро — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_eur(), 1)}</b></ins>
Фунт — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_gbp(), 1)}</b></ins>
Юань — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_cny(), 1)}</b></ins>
Франк — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_chf(), 1)}</b></ins>
Иена — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_jpy(), 1)}</b></ins>
Доллар — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_cad(), 1)}</b></ins>
Дирхам — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_aed(), 1)}</b></ins>
Бат — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_thb(), 1)}</b></ins>
Тенге — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_kzt(), 1)}</b></ins>
Манат — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_azn(), 1)}</b></ins>
''', reply_markup=mainkbd, parse_mode='HTML'
)
elif users_id_and_selected_language[message.chat.id] == 'en':
await mybot.send_message(
message.chat.id,
f'''
Dollar — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd(), 1)}</b></ins>
Euro — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_eur(), 1)}</b></ins>
Pound — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_gbp(), 1)}</b></ins>
Yuan — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_cny(), 1)}</b></ins>
Franc — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_chf(), 1)}</b></ins>
Yen — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_jpy(), 1)}</b></ins>
Dollar — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_cad(), 1)}</b></ins>
Dirham — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_aed(), 1)}</b></ins>
Baht — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_thb(), 1)}</b></ins>
Tenge — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_kzt(), 1)}</b></ins>
Manat — <ins><b>{round(number_of_currency_for_converting * end_convert_for_usd() * end_convert_for_azn(), 1)}</b></ins>
''', reply_markup=mainkbd, parse_mode='HTML'
)
И так дальше с 12 валютами
Например, я с одного аккаунта пишу боту Валюту, потом количество, и пока он не отправит сообщение с курсами, он не ответит другому аккаунту, с таким же запросом(бот отправляет сообщение с курсами секунд 10, там нужно парсануть более 20 сайтов для него)
Может быть это из-за не использования asyncio? Или в чём может быть ошибка?