Answer the question
In order to leave comments, you need to log in
Nothing is displayed in the chat, but in the console (bottom) how to fix it?
from covid import Covid
import telebot
import config
bot = telebot.TeleBot(config.TOKEN)
covid = Covid()
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "Начнем")
@bot.message_handler(content_types=['text'])
def start(message):
final_message = ""
get_message_bot = message.text.strip().lower()
if get_message_bot == "США":
location = covid.get_status_by_country_name("us")
elif get_message_bot == "Украина":
location = covid.get_status_by_country_name("Ukraine")
elif get_message_bot == "Россия":
location = covid.get_status_by_country_name("russia")
elif get_message_bot == "Беларусь":
location = covid.get_status_by_country_name("Belarus")
elif get_message_bot == "Казахстан":
location = covid.get_status_by_country_name("Kazakhstan")
elif get_message_bot == "Италия":
location = covid.get_status_by_country_name("italy")
elif get_message_bot == "Франция":
location = covid.get_status_by_country_name("france")
elif get_message_bot == "Германия":
location = covid.get_status_by_country_name("Germany")
elif get_message_bot == "Япония":
location = covid.get_status_by_country_name("Japan")
final_message = f"<u>Данные по стране:</u>\n<b>Заболевших: </b>{location['confirmed']:,}\n<b>Умерших: </b>{location['deaths']:,}\n<b>Выздоровевших: </b>{location['recovered']:,}\n<b>Болеющих: </b>{location['active']:,}"
else:
location = covid.get_status_by_country_name("russia")
bot.send_message(message.chat.id, final_message, parse_mode='html')
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
The logic of your check is not clear to me. First, you convert the string to lowercase, and then compare it with a string that begins with a capital letter. Lots of if, elif, and else constructs are bad. I would replace them all with a dictionary.
For example, like this:
from covid import Covid
import telebot
import config
bot = telebot.TeleBot(config.TOKEN)
covid = Covid()
country = { 'сша':'Us',
'украина':'Ukraine',
'россия':'Russia',
'беларусь':'Belarus',
'казахстан':'Kazakhstan',
'италия':'Italy',
'франция':'France',
'германия':'Germany',
'япония':'Japan',
}
@bot.message_handler(commands=['start', 'help'])
def send_welcome(message):
bot.reply_to(message, "Начнем")
@bot.message_handler(content_types=['text'])
def start(message):
get_message_bot = message.text.strip().lower()
location = covid.get_status_by_country_name(country.get(get_message_bot,'russia'))
final_message = f"<u>Данные по стране:</u>\n<b>Заболевших: </b>{location['confirmed']:,}\n<b>Умерших: </b>{location['deaths']:,}\n<b>Выздоровевших: </b>{location['recovered']:,}\n<b>Болеющих: </b>{location['active']:,}"
bot.send_message(message.chat.id, final_message, parse_mode='html')
bot.polling(none_stop=True)
location = covid.get_status_by_country_name(country.get(get_message_bot,'russia'))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question