def find_weather(message): try: observation = owm.weather_at_place(message.text) place = message.text w = observation.get_weather() temp_min = w.get_temperature('celsius')['temp_min'] # {'temp_max': 10.5, 'temp': 9.7, 'temp_min': 9.0} temp_max = w.get_temperature('celsius')['temp_max'] humidity = w.get_humidity() # 87 wind = w.get_wind()['speed'] # {'speed': 4.6, 'deg': 330} answer = ('Погода в ' + place + "\n\n") answer += ('Тут сейчас ' + w.get_detailed_status() + "\n") if temp_min == temp_max: answer += ('Температура ' + str(temp_min) + ' градусов' + "\n") else: if min(temp_max, temp_min) < 0: answer += ('Температура от ' + str(temp_max) + ' до ' + str(temp_min) + ' градусов' + "\n") else: answer += ('Температура от ' + str(temp_min) + ' до ' + str(temp_max) + ' градусов' + "\n") answer += ('Влажность ' + str(humidity) + '%' + "\n") answer += ('Скорость ветра ' + str(wind) + 'м/c') bot.send_message(message.chat.id, answer) markup = types.ReplyKeyboardMarkup(one_time_keyboard=True) markup.add('Да', 'Нет') msg = bot.reply_to(message, 'Узнать погоду в другом городе?', reply_markup=markup) bot.register_next_step_handler(msg, reply_find_weather) except: answer: str = 'Неправильно ввел город. Давай ещё раз!' bot.send_message(message.chat.id, answer) find_place(message)
def find_weight(message): message.text = (message.text).replace(',', '.') try: message.text = float(message.text) if message.text > 0: global weight weight = message.text imt_calculation(message) else: bot.send_message(message.chat.id, 'Вес не может быть <=0, давай ещё раз!') input_weight(message) except: bot.send_message(message.chat.id, 'Может ты не так меня понял?') input_weight(message)
def find_height(message): message.text = message.text.replace(',', '.') try: message.text = float(message.text) if message.text > 0: global height height = message.text input_weight(message) else: bot.send_message(message.chat.id, 'Рост не может быть <=0, давай ещё раз!') input_height(message) except: bot.send_message(message.chat.id, 'Что ты написал вообще?') input_height(message)
def imt_calculation(message): imt_result = round((weight / (height / 100)**2), 2) weight_interpreter = '' if imt_result > 40: weight_interpreter = ': ожирение 3-й степени' if 35 <= imt_result < 40: weight_interpreter = ': ожирение 2-й степени' if 30 <= imt_result < 35: weight_interpreter = ': ожирение 1-й степени' if 25 <= imt_result < 30: weight_interpreter = ': предожирение (избыточная масса)' if 18.5 <= imt_result < 25: weight_interpreter = ': нормальный вес (оптимальный)' if 16 <= imt_result < 18.5: weight_interpreter = ': недостаточный вес' if imt_result < 16: weight_interpreter = ': анорексия (дефицит веса)' weight_recommended = round(21.75 * (height / 100)**2, 2) bot.send_message( message.chat.id, str(imt_result) + weight_interpreter + "\n" + 'Рекомендуемый вес для данного роста ' + str(weight_recommended)) bot.send_message(message.chat.id, '/start')
def reply_find_weather(message): if message.text == 'Да': msg = bot.reply_to(message, 'Напиши город или страну') bot.register_next_step_handler(msg, find_weather) else: bot.send_message(message.chat.id, '/start')