Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import COVID19Py
- import telebot
- from telebot import types
- from flask import Flask, request
- covid19 = COVID19Py.COVID19()
- TOKEN = 'Your token'
- bot = telebot.TeleBot(TOKEN, threaded=False)
- secret = 'Your secret key'
- url = 'https://8e277600.ngrok.io/' + secret
- bot.remove_webhook()
- bot.set_webhook(url=url)
- app = Flask(__name__)
- user_data = {}
- class User:
- def __init__(self, age):
- self.age = age
- self.temperature = ''
- self.cough = ''
- self.check = ''
- @bot.message_handler(commands=["start"])
- def main(message):
- markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
- but_test = types.KeyboardButton('Онлайн тест на коронавирус')
- but_info = types.KeyboardButton('Онлайн иноформация о коронавирусе')
- markup.add(but_test)
- markup.add(but_info)
- msg = bot.send_message(message.chat.id, message.from_user.first_name + " " + message.from_user.last_name +
- ", здесь вы сможете узнать статистику о заболевших коронавирусом! Для начала работы "
- "Телеграм Бота необходимо выбрать, что Вас интересует: ",
- reply_markup=markup)
- bot.register_next_step_handler(msg, choose_info)
- @app.route('/' + secret, methods=['POST'])
- def webhook():
- update = telebot.types.Update.de_json(request.stream.read().decode('utf-8'))
- bot.process_new_updates([update])
- return '!', 200
- @bot.message_handler(commands=["Main_Menu"])
- def inline(message):
- key = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
- but_reg = types.KeyboardButton(text='Онлайн тест на коронавирус')
- but_search = types.KeyboardButton(text='Онлайн иноформация о коронавирусе')
- key.add(but_reg)
- key.add(but_search)
- msg = bot.send_message(message.chat.id, "Выберите, что Вас интересует?",
- reply_markup=key)
- bot.register_next_step_handler(msg, choose_info)
- def choose_info(message):
- markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
- but_main = types.KeyboardButton('/Main_Menu')
- markup.add(but_main)
- if message.text == 'Онлайн тест на коронавирус':
- key = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
- but_one = types.KeyboardButton('Мне меньше 18 лет')
- but_two = types.KeyboardButton('18 - 30 лет')
- but_three = types.KeyboardButton('30 - 50 лет')
- but_four = types.KeyboardButton('50 - 65 лет')
- but_five = types.KeyboardButton('Старше 65 лет')
- key.add(but_one)
- key.add(but_two, but_three)
- key.add(but_four, but_five)
- msg = bot.send_message(message.chat.id, "Сколько Вам лет?", reply_markup=key)
- bot.register_next_step_handler(msg, test_age)
- elif message.text == 'Онлайн иноформация о коронавирусе':
- key = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
- but_main_menu = types.KeyboardButton('Назад')
- but_all_countries = types.KeyboardButton('Заболевших во всем мире')
- but_uzb = types.KeyboardButton('Узбекистан')
- but_kz = types.KeyboardButton('Казахстан')
- but_rus = types.KeyboardButton('Россия')
- but_ita = types.KeyboardButton('Италия')
- but_spain = types.KeyboardButton('Испания')
- but_usa = types.KeyboardButton('США')
- key.add(but_uzb, but_kz)
- key.add(but_rus, but_usa)
- key.add(but_ita, but_spain)
- key.add(but_all_countries)
- key.add(but_main_menu)
- msg = bot.send_message(message.chat.id, "Выберите страну для получения информации о количестве заболевших: ",
- reply_markup=key)
- bot.register_next_step_handler(msg, covid_19_search)
- else:
- msg = bot.send_message(message.chat.id, "Возврат в главное меню: /Main_Menu")
- bot.register_next_step_handler(msg, inline)
- def covid_19_search(message):
- if message.text == 'Узбекистан':
- location_one = covid19.getLocationByCountryCode("UZ")
- dic = location_one[0]
- latest_one = dic.get('latest')
- final_message = f"<u>Данные по стране</u>\n\nСтрана: {dic.get('country')} \nНаселение: {dic.get('country_population'):,}" \
- f"\nПоследнее обновление: {dic.get('last_updated')} \n<b>Заболевших: </b>" \
- f"{latest_one.get('confirmed'):,} \n<b>Сметрей: </b>{latest_one.get('deaths'):,}"
- bot.send_message(message.chat.id, text=final_message, parse_mode='html')
- elif message.text == 'Казахстан':
- location_one = covid19.getLocationByCountryCode("KZ")
- dic = location_one[0]
- latest_one = dic.get('latest')
- final_message = f"<u>Данные по стране</u>\n\nСтрана: {dic.get('country')} \nНаселение: {dic.get('country_population'):,}" \
- f"\nПоследнее обновление: {dic.get('last_updated')} \n<b>Заболевших: </b>" \
- f"{latest_one.get('confirmed'):,} \n<b>Сметрей: </b>{latest_one.get('deaths'):,}"
- bot.send_message(message.chat.id, text=final_message, parse_mode='html')
- elif message.text == 'Россия':
- location_one = covid19.getLocationByCountryCode("RU")
- dic = location_one[0]
- latest_one = dic.get('latest')
- final_message = f"<u>Данные по стране</u>\n\nСтрана: {dic.get('country')} \nНаселение: {dic.get('country_population'):,}" \
- f"\nПоследнее обновление: {dic.get('last_updated')} \n<b>Заболевших: </b>" \
- f"{latest_one.get('confirmed'):,} \n<b>Сметрей: </b>{latest_one.get('deaths'):,}"
- bot.send_message(message.chat.id, text=final_message, parse_mode='html')
- elif message.text == 'США':
- location_one = covid19.getLocationByCountryCode("US")
- dic = location_one[0]
- latest_one = dic.get('latest')
- final_message = f"<u>Данные по стране</u>\n\nСтрана: {dic.get('country')} \nНаселение: {dic.get('country_population'):,}" \
- f"\nПоследнее обновление: {dic.get('last_updated')} \n<b>Заболевших: </b>" \
- f"{latest_one.get('confirmed'):,} \n<b>Сметрей: </b>{latest_one.get('deaths'):,}"
- bot.send_message(message.chat.id, text=final_message, parse_mode='html')
- elif message.text == 'Италия':
- location_one = covid19.getLocationByCountryCode("IT")
- dic = location_one[0]
- latest_one = dic.get('latest')
- final_message = f"<u>Данные по стране</u>\n\nСтрана: {dic.get('country')} \nНаселение: {dic.get('country_population'):,}" \
- f"\nПоследнее обновление: {dic.get('last_updated')} \n<b>Заболевших: </b>" \
- f"{latest_one.get('confirmed'):,} \n<b>Сметрей: </b>{latest_one.get('deaths'):,}"
- bot.send_message(message.chat.id, text=final_message, parse_mode='html')
- elif message.text == 'Испания':
- location_one = covid19.getLocationByCountryCode("ES")
- dic = location_one[0]
- latest_one = dic.get('latest')
- final_message = f"<u>Данные по стране</u>\n\nСтрана: {dic.get('country')} \nНаселение: {dic.get('country_population'):,}" \
- f"\nПоследнее обновление: {dic.get('last_updated')} \n<b>Заболевших: </b>" \
- f"{latest_one.get('confirmed'):,} \n<b>Сметрей: </b>{latest_one.get('deaths'):,}"
- bot.send_message(message.chat.id, text=final_message, parse_mode='html')
- elif message.text == 'Заболевших во всем мире':
- latest = covid19.getLatest()
- dic = latest
- final_message = f"<u>Данные по всему миру</u> \n\n<b>Заболевших: </b>"\
- f"{dic.get('confirmed'):,} \n<b>Сметрей: </b>{dic.get('deaths'):,}"
- bot.send_message(message.chat.id, text=final_message, parse_mode='html')
- else:
- key = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
- but_main = types.KeyboardButton('Главное меню')
- key.add(but_main)
- msg = bot.send_message(message.chat.id, "Возврат в главное меню", reply_markup=key)
- bot.register_next_step_handler(msg, inline)
- return
- msg = bot.send_message(message.chat.id, "Выберите страну для получения информации о количестве заболевших: ")
- bot.register_next_step_handler(msg, covid_19_search)
- return
- def test_age(message):
- try:
- key = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
- but_one = types.KeyboardButton('36,6')
- but_two = types.KeyboardButton('37')
- but_three = types.KeyboardButton('37 - 38')
- but_four = types.KeyboardButton('38 - 39')
- but_five = types.KeyboardButton('39 - 40')
- key.add(but_one, but_two)
- key.add(but_three)
- key.add(but_four)
- key.add(but_five)
- user_id = message.from_user.id
- user_data[user_id] = User(message.text)
- if message.text == 'Мне меньше 18 лет':
- bot.send_message(message.chat.id, 'Отлично мой юный друг, продолжаем!')
- elif message.text == '18 - 30 лет':
- bot.send_message(message.chat.id, 'Отлично, продолжаем!')
- elif message.text == '30 - 50 лет':
- bot.send_message(message.chat.id, 'Отлично, Вы в самом рассвете сил, продолжаем!')
- elif message.text == '50 - 65 лет':
- bot.send_message(message.chat.id, 'Отлично, Вы хорошо держитесь, продолжаем!')
- elif message.text == 'Старше 65 лет':
- bot.send_message(message.chat.id, 'Отлично, Вы полны позитива, продолжаем!')
- else:
- key = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
- but_one = types.KeyboardButton('Мне меньше 18 лет')
- but_two = types.KeyboardButton('18 - 30 лет')
- but_three = types.KeyboardButton('30 - 50 лет')
- but_four = types.KeyboardButton('50 - 65 лет')
- but_five = types.KeyboardButton('Старше 65 лет')
- key.add(but_one)
- key.add(but_two, but_three)
- key.add(but_four, but_five)
- msg = bot.send_message(message.chat.id, 'Нажмите на кнопки, для выбора возраста!', reply_markup=key)
- bot.register_next_step_handler(msg, test_age)
- return
- msg = bot.send_message(message.chat.id, 'Какая у Вас температура? ', reply_markup=key)
- bot.register_next_step_handler(msg, test_temperature)
- except Exception:
- msg = bot.reply_to(message, 'Что-то пошло не так!')
- bot.register_next_step_handler(msg, test_age)
- return
- def test_temperature(message):
- try:
- user_id = message.from_user.id
- user = user_data[user_id]
- user.temperature = message.text.lower()
- key = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
- but_all = types.KeyboardButton('Есть все или несколько симптомов')
- but_not_all = types.KeyboardButton('Нет симптомов')
- key.add(but_all)
- key.add(but_not_all)
- if message.text == '36,6':
- bot.send_message(message.chat.id, 'Отлично, продолжаем!')
- elif message.text == '37':
- bot.send_message(message.chat.id, 'Могло бы быть и лучше!')
- elif message.text == '37 - 38':
- bot.send_message(message.chat.id, 'Что-то вы приболели!')
- elif message.text == '38 - 39':
- bot.send_message(message.chat.id, 'Как так!?')
- elif message.text == '39 - 40':
- bot.send_message(message.chat.id, 'Мм, это не хорошо!')
- else:
- key = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
- but_one = types.KeyboardButton('36,6')
- but_two = types.KeyboardButton('37')
- but_three = types.KeyboardButton('37 - 38')
- but_four = types.KeyboardButton('38 - 39')
- but_five = types.KeyboardButton('39 - 40')
- key.add(but_one, but_two)
- key.add(but_three)
- key.add(but_four)
- key.add(but_five)
- msg = bot.send_message(message.chat.id, 'Нажмите на кнопки, для выбора температуры!', reply_markup=key)
- bot.register_next_step_handler(msg, test_temperature)
- return
- msg = bot.send_message(message.chat.id, 'Какие у Вас симптомы (головная боль, сухой кашель, насморк)?',
- reply_markup=key)
- bot.register_next_step_handler(msg, test_cough)
- except Exception:
- msg = bot.reply_to(message, 'Что-то пошло не так!')
- bot.register_next_step_handler(msg, test_temperature)
- return
- def test_cough(message):
- try:
- user_id = message.from_user.id
- user = user_data[user_id]
- user.cough = message.text
- question = 'Проверьте вашу информацию \n\nВозраст: ' + user.age + '\nТемпература: ' + user.temperature + \
- '\nСимптомы: ' + user.cough
- markup = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
- but_yes = types.KeyboardButton(text='подтверждаю')
- but_no = types.KeyboardButton(text='есть ошибка')
- markup.add(but_yes, but_no)
- if message.text == 'Есть все или несколько симптомов':
- bot.send_message(message.chat.id, 'Возможно, это просто простуда!')
- elif message.text == 'Нет симптомов':
- bot.send_message(message.chat.id, 'Отлично!')
- else:
- key = types.ReplyKeyboardMarkup(one_time_keyboard=True, resize_keyboard=True)
- but_all = types.KeyboardButton('Есть все или несколько симптомов')
- but_not_all = types.KeyboardButton('Нет симптомов')
- key.add(but_all)
- key.add(but_not_all)
- msg = bot.send_message(message.chat.id, 'Нажмите на кнопки, для выбора варианта!')
- bot.register_next_step_handler(msg, test_cough)
- return
- msg = bot.send_message(message.chat.id, text=question,
- reply_markup=markup)
- bot.register_next_step_handler(msg, test_check)
- except Exception:
- msg = bot.reply_to(message, 'Что-то пошло не так!')
- bot.register_next_step_handler(msg, test_cough)
- return
- def test_check(message):
- try:
- user_id = message.from_user.id
- user = user_data[user_id]
- user.check = message.text
- if message.text == 'подтверждаю':
- if user.age == 'Старше 65 лет':
- if user.temperature == '37 - 38' or user.temperature == '38 - 39' or user.temperature == '39 - 40':
- if user.cough == 'Есть все или несколько симптомов':
- msg = bot.send_message(message.chat.id,
- 'Возможно это коронавирус, стоит срочно обратиться к врачу!!! '
- 'Вы в зоне риска! В любом случае это опасный вирус, '
- 'берегите себя и своих близких!')
- bot.register_next_step_handler(msg, inline)
- else:
- msg = bot.send_message(message.chat.id, 'Если температура не спадает уже несколько дней, то '
- 'возможно это коронавирус, так как иногда болезнь может '
- 'протекать без явных симптомов, стоит обратиться '
- 'к врачу!!! Вы в зоне риска!'
- 'В любом случае это опасный вирус, берегите себя и своих '
- 'близких!')
- bot.register_next_step_handler(msg, inline)
- else:
- msg = bot.send_message(message.chat.id,
- 'Вы здоровы и полны сил! Берегите себя и своих близких!')
- bot.register_next_step_handler(msg, inline)
- elif user.age == 'Мне меньше 18 лет' or user.age == '18 - 30 лет' or user.age == '30 - 50 лет' or \
- user.age == '50 - 65 лет':
- if user.temperature == '37 - 38' or user.temperature == '38 - 39' or user.temperature == '39 - 40':
- if user.cough == 'Есть все или несколько симптомов':
- msg = bot.send_message(message.chat.id,
- 'Возможно это коронавирус, стоит обратиться '
- 'к врачу!!! Если у Вас нет хранических заболеваний, то '
- 'Вы не в зоне риска, но стоит провериться!'
- 'В любом случае это опасный вирус, берегите себя и своих '
- 'близких!')
- bot.register_next_step_handler(msg, inline)
- else:
- msg = bot.send_message(message.chat.id, 'Если температура не спадает уже несколько дней, то '
- 'возможно это коронавирус, так как иногда болезнь может '
- 'протекать без явных симптомов, стоит обратиться '
- 'к врачу!!! Если у Вас нет хранических '
- 'заболеваний, то '
- 'Вы не в зоне риска, но стоит провериться! '
- 'В любом случае это опасный вирус, берегите себя и своих '
- 'близких!')
- bot.register_next_step_handler(msg, inline)
- else:
- msg = bot.send_message(message.chat.id, 'Вы здоровы и полны сил! Берегите себя и своих близких!')
- bot.register_next_step_handler(msg, inline)
- elif message.text == 'есть ошибка':
- markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
- but_mm = types.KeyboardButton('Главное меню')
- markup.add(but_mm)
- msg = bot.send_message(message.chat.id, 'Возврат в главное меню', reply_markup=markup)
- bot.register_next_step_handler(msg, inline)
- return
- else:
- bot.reply_to(message, 'Что-то пошло не так!')
- markup = types.ReplyKeyboardMarkup(resize_keyboard=True, row_width=2)
- but_mm = types.KeyboardButton('/Main_Menu')
- markup.add(but_mm)
- bot.send_message(message.chat.id, '/Main_Menu',
- reply_markup=markup)
- except Exception:
- msg = bot.reply_to(message, 'Что-то пошло не так!')
- bot.register_next_step_handler(msg, choose_info)
- return
- if __name__ == '__main__':
- app.run()
Advertisement
Add Comment
Please, Sign In to add comment