Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import telebot
- from telebot import types
- import COVID19Py
- import config
- covid19 = COVID19Py.COVID19()
- bot = telebot.TeleBot(config.TOKEN)
- @bot.message_handler(commands=['start'])
- def start(message):
- markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
- btn1 = types.KeyboardButton('Во всём мире')
- btn2 = types.KeyboardButton('Россия')
- btn3 = types.KeyboardButton('Украина')
- btn4 = types.KeyboardButton('США')
- btn5 = types.KeyboardButton('Казахстан')
- btn6 = types.KeyboardButton('Узбекистан')
- btn7 = types.KeyboardButton('Китай')
- btn8 = types.KeyboardButton('Испания')
- btn9 = types.KeyboardButton('Италия')
- markup.add(btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9)
- send_message = f"<b>Привет {message.from_user.first_name}!</b>\nЧтобы получить данные о коронавирусе напишите " \
- f"название страны, например: США, Украина, Россия и так далее\n\n"
- bot.send_message(message.chat.id, send_message, parse_mode='html', reply_markup=markup)
- @bot.message_handler(content_types=['text'])
- def mess(message):
- final_message = ""
- get_message_bot = message.text.replace("ё", "е").lower()
- if get_message_bot == "во всем мире":
- try:
- location = covid19.getLatest()
- print(location)
- final_message = f"<u>Данные по всему миру:</u>\n<b>Заболевших: </b>{location['confirmed']:,}\n<b>Сметрей: </b>{location['deaths']:,}"
- bot.send_message(message.chat.id, final_message, parse_mode='html')
- except Exception as e:
- print(e)
- if get_message_bot == "россия":
- try:
- location = covid19.getLocationByCountryCode("RU")
- print(location[0].get('latest')['confirmed'])
- final_message = f"<u>Данные из России:</u>\n<b>Заболевших: </b>{location[0].get('latest')['confirmed']:,}\n<b>Сметрей: </b>{location[0].get('latest')['deaths']:,}"
- bot.send_message(message.chat.id, final_message, parse_mode='html')
- except Exception as e:
- print(e)
- if get_message_bot == "украина":
- try:
- location = covid19.getLocationByCountryCode("UA")
- print(location[0].get('latest')['confirmed'])
- final_message = f"<u>Данные с Украины:</u>\n<b>Заболевших: </b>{location[0].get('latest')['confirmed']:,}\n<b>Сметрей: </b>{location[0].get('latest')['deaths']:,}"
- bot.send_message(message.chat.id, final_message, parse_mode='html')
- except Exception as e:
- print(e)
- if get_message_bot == "сша":
- try:
- location = covid19.getLocationByCountryCode("US")
- print(location[0].get('latest')['confirmed'])
- final_message = f"<u>Данные из США:</u>\n<b>Заболевших: </b>{location[0].get('latest')['confirmed']:,}\n<b>Сметрей: </b>{location[0].get('latest')['deaths']:,}"
- bot.send_message(message.chat.id, final_message, parse_mode='html')
- except Exception as e:
- print(e)
- if get_message_bot == "казахстан":
- try:
- location = covid19.getLocationByCountryCode("KZ")
- print(location[0].get('latest')['confirmed'])
- final_message = f"<u>Данные из Казахстана:</u>\n<b>Заболевших: </b>{location[0].get('latest')['confirmed']:,}\n<b>Сметрей: </b>{location[0].get('latest')['deaths']:,}"
- bot.send_message(message.chat.id, final_message, parse_mode='html')
- except Exception as e:
- print(e)
- if get_message_bot == "узбекистан":
- try:
- location = covid19.getLocationByCountryCode("UZ")
- print(location[0].get('latest')['confirmed'])
- final_message = f"<u>Данные из Узбекистана:</u>\n<b>Заболевших: </b>{location[0].get('latest')['confirmed']:,}\n<b>Сметрей: </b>{location[0].get('latest')['deaths']:,}"
- bot.send_message(message.chat.id, final_message, parse_mode='html')
- except Exception as e:
- print(e)
- if get_message_bot == "китай":
- try:
- location = covid19.getLocationByCountryCode("CN")
- print(location[0].get('latest')['confirmed'])
- final_message = f"<u>Данные из Китая:</u>\n<b>Заболевших: </b>{location[0].get('latest')['confirmed']:,}\n<b>Сметрей: </b>{location[0].get('latest')['deaths']:,}"
- bot.send_message(message.chat.id, final_message, parse_mode='html')
- except Exception as e:
- print(e)
- if get_message_bot == "испания":
- try:
- location = covid19.getLocationByCountryCode("ES")
- print(location[0].get('latest')['confirmed'])
- final_message = f"<u>Данные из Испании:</u>\n<b>Заболевших: </b>{location[0].get('latest')['confirmed']:,}\n<b>Сметрей: </b>{location[0].get('latest')['deaths']:,}"
- bot.send_message(message.chat.id, final_message, parse_mode='html')
- except Exception as e:
- print(e)
- if get_message_bot == "италия":
- try:
- location = covid19.getLocationByCountryCode("IT")
- print(location[0].get('latest')['confirmed'])
- final_message = f"<u>Данные из Италии:</u>\n<b>Заболевших: </b>{location[0].get('latest')['confirmed']:,}\n<b>Сметрей: </b>{location[0].get('latest')['deaths']:,}"
- bot.send_message(message.chat.id, final_message, parse_mode='html')
- except Exception as e:
- print(e)
- while True:
- try:
- bot.polling()
- except:
- time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement