import telebot import requests import COVID19Py import pprint TOKEN = '973885852:AAE1headHq5WOhEnQvn4Cj2nZmzk6NUg750' covid = COVID19Py.COVID19() bot = telebot.TeleBot(TOKEN) COUNTRIES = { "украина" : "UA", "россия" : "RU", "сша" : "US", "польша" : "PL", "канада" : "CA", "китай" : "CN", } def compare_lists(input_text, dictin): spl1 = set(list(input_text)) for i in dictin.keys(): spl2 = set(list(i)) if spl1 >= spl2: return i def figure_country_code(final_message): for i in COUNTRIES.keys(): if final_message == i: return COUNTRIES[i] def select_country_name(value): for k, v in COUNTRIES.items(): if v == value: return k # string = figure_country_code("украниа") # print(string) # print(figure_country_code("украина")) # print(bool(figure_country_code("украна"))) @bot.message_handler(commands = ['start']) def start(message): start_message = f"<b>Привет {message.from_user.first_name}</b>\nВведите страну" bot.send_message(message.chat.id, start_message, parse_mode = 'html') @bot.edited_message_handler(content_types = ['text']) @bot.message_handler(content_types = ['text']) def mess(message): final_message = "" message_by_user = message.text.strip().lower() final_message_by_user = compare_lists(message_by_user, COUNTRIES) country_code = figure_country_code(final_message_by_user) country_name = select_country_name(country_code) if bool(country_code): location = covid.getLocationByCountryCode(country_code) # if get_message_by_user == "сша": # location = covid.getLocationByCountryCode("US") # elif get_message_by_user == "украина": # location = covid.getLocationByCountryCode("UA") # elif get_message_by_user == "россия" or get_message_by_user == "росия": # location = covid.getLocationByCountryCode("RU") else: location = covid.getLatest() final_message = f"<b>У меня нету информации по этой стране</b>\n<u>Данные по всему миру:</u>\n<b>Заболевшие: </b>{location['confirmed']}\n" if final_message == "": date = location[0]['last_updated'].split("T") time = date[1].split(".") final_message = f"<b>{country_name.upper()}</b>\n<u>Информация по стране:</u>\n<b>Население страны: </b>{location[0]['country_population']}\n\<b>Последние обновление : </b>{date[0]} {time[0]}\n<u>Последние данные:</u>\n<b>Заболевших: </b>{location[0]['latest']['confirmed']}\n<b>Смертей: </b>{location[0]['latest']['deaths']}\n" bot.send_message(message.chat.id, final_message, parse_mode='html') bot.polling(none_stop = True)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question