Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.38 KB | None | 0 0
  1. import telebot
  2. from telebot import types
  3. import COVID19Py
  4. import config
  5.  
  6.  
  7. covid19 = COVID19Py.COVID19()
  8. bot = telebot.TeleBot(config.TOKEN)
  9.  
  10.  
  11. @bot.message_handler(commands=['start'])
  12. def start(message):
  13.     markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=3)
  14.     btn1 = types.KeyboardButton('Во всём мире')
  15.     btn2 = types.KeyboardButton('Россия')
  16.     btn3 = types.KeyboardButton('Украина')
  17.     btn4 = types.KeyboardButton('США')
  18.     btn5 = types.KeyboardButton('Казахстан')
  19.     btn6 = types.KeyboardButton('Узбекистан')
  20.     btn7 = types.KeyboardButton('Китай')
  21.     btn8 = types.KeyboardButton('Испания')
  22.     btn9 = types.KeyboardButton('Италия')
  23.     markup.add(btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9)
  24.  
  25.     send_message = f"<b>Привет {message.from_user.first_name}!</b>\nЧтобы получить данные о коронавирусе напишите " \
  26.         f"название страны, например: США, Украина, Россия и так далее\n\n"
  27.     bot.send_message(message.chat.id, send_message, parse_mode='html', reply_markup=markup)
  28.  
  29.  
  30.  
  31. @bot.message_handler(content_types=['text'])
  32. def mess(message):
  33.     final_message = ""
  34.     get_message_bot = message.text.replace("ё", "е").lower()
  35.     if get_message_bot == "во всем мире":
  36.         try:
  37.             location = covid19.getLatest()
  38.             print(location)
  39.             final_message = f"<u>Данные по всему миру:</u>\n<b>Заболевших: </b>{location['confirmed']:,}\n<b>Сметрей: </b>{location['deaths']:,}"
  40.             bot.send_message(message.chat.id, final_message, parse_mode='html')
  41.         except Exception as e:
  42.             print(e)
  43.     if get_message_bot == "россия":
  44.         try:
  45.             location = covid19.getLocationByCountryCode("RU")
  46.             print(location[0].get('latest')['confirmed'])
  47.             final_message = f"<u>Данные из России:</u>\n<b>Заболевших: </b>{location[0].get('latest')['confirmed']:,}\n<b>Сметрей: </b>{location[0].get('latest')['deaths']:,}"
  48.             bot.send_message(message.chat.id, final_message, parse_mode='html')
  49.         except Exception as e:
  50.             print(e)
  51.    
  52.     if get_message_bot == "украина":
  53.         try:
  54.             location = covid19.getLocationByCountryCode("UA")
  55.             print(location[0].get('latest')['confirmed'])
  56.             final_message = f"<u>Данные с Украины:</u>\n<b>Заболевших: </b>{location[0].get('latest')['confirmed']:,}\n<b>Сметрей: </b>{location[0].get('latest')['deaths']:,}"
  57.             bot.send_message(message.chat.id, final_message, parse_mode='html')
  58.         except Exception as e:
  59.             print(e)
  60.  
  61.     if get_message_bot == "сша":
  62.         try:
  63.             location = covid19.getLocationByCountryCode("US")
  64.             print(location[0].get('latest')['confirmed'])
  65.             final_message = f"<u>Данные из США:</u>\n<b>Заболевших: </b>{location[0].get('latest')['confirmed']:,}\n<b>Сметрей: </b>{location[0].get('latest')['deaths']:,}"
  66.             bot.send_message(message.chat.id, final_message, parse_mode='html')
  67.         except Exception as e:
  68.             print(e)
  69.  
  70.     if get_message_bot == "казахстан":
  71.         try:
  72.             location = covid19.getLocationByCountryCode("KZ")
  73.             print(location[0].get('latest')['confirmed'])
  74.             final_message = f"<u>Данные из Казахстана:</u>\n<b>Заболевших: </b>{location[0].get('latest')['confirmed']:,}\n<b>Сметрей: </b>{location[0].get('latest')['deaths']:,}"
  75.             bot.send_message(message.chat.id, final_message, parse_mode='html')
  76.         except Exception as e:
  77.             print(e)
  78.  
  79.  
  80.     if get_message_bot == "узбекистан":
  81.         try:
  82.             location = covid19.getLocationByCountryCode("UZ")
  83.             print(location[0].get('latest')['confirmed'])
  84.             final_message = f"<u>Данные из Узбекистана:</u>\n<b>Заболевших: </b>{location[0].get('latest')['confirmed']:,}\n<b>Сметрей: </b>{location[0].get('latest')['deaths']:,}"
  85.             bot.send_message(message.chat.id, final_message, parse_mode='html')
  86.         except Exception as e:
  87.             print(e)
  88.  
  89.     if get_message_bot == "китай":
  90.         try:
  91.             location = covid19.getLocationByCountryCode("CN")
  92.             print(location[0].get('latest')['confirmed'])
  93.             final_message = f"<u>Данные из Китая:</u>\n<b>Заболевших: </b>{location[0].get('latest')['confirmed']:,}\n<b>Сметрей: </b>{location[0].get('latest')['deaths']:,}"
  94.             bot.send_message(message.chat.id, final_message, parse_mode='html')
  95.         except Exception as e:
  96.             print(e)
  97.  
  98.     if get_message_bot == "испания":
  99.         try:
  100.             location = covid19.getLocationByCountryCode("ES")
  101.             print(location[0].get('latest')['confirmed'])
  102.             final_message = f"<u>Данные из Испании:</u>\n<b>Заболевших: </b>{location[0].get('latest')['confirmed']:,}\n<b>Сметрей: </b>{location[0].get('latest')['deaths']:,}"
  103.             bot.send_message(message.chat.id, final_message, parse_mode='html')
  104.         except Exception as e:
  105.             print(e)
  106.  
  107.     if get_message_bot == "италия":
  108.         try:
  109.             location = covid19.getLocationByCountryCode("IT")
  110.             print(location[0].get('latest')['confirmed'])
  111.             final_message = f"<u>Данные из Италии:</u>\n<b>Заболевших: </b>{location[0].get('latest')['confirmed']:,}\n<b>Сметрей: </b>{location[0].get('latest')['deaths']:,}"
  112.             bot.send_message(message.chat.id, final_message, parse_mode='html')
  113.         except Exception as e:
  114.             print(e)
  115.  
  116.  
  117. while True:
  118.     try:
  119.         bot.polling()
  120.     except:
  121.         time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement