Answer the question
In order to leave comments, you need to log in
Telegram weather bot error "City not found"?
import pyowm
import telebot
owm = pyowm.OWM(xxxxxxxxxxxxxxxxx, {'language': 'ru'})
bot = telebot.TeleBot('xxxxxxxxxxxxxxxxxxxxxx')
@bot.message_handler(content_types=['text'])
def send_echo(message):
try:
observation = owm.weather_at_place(message.text)
w = observation.get_weather()
temp = w.get_temperature('celsius')['temp']
answer = f"В городе {message.text} сейчас {w.get_detailed_status()} \n"
answer += f"Приблизительная температура {round(temp)} градусов\n\n"
if temp < 0:
answer += 'Сейчас температура ниже нуля, одевайся теплее!'
elif temp < 20:
answer += 'Сейчас прохладно, стоит потеплей одеться!'
else:
answer += 'Сейчас достаточно тепло, можно одеться легко!'
bot.send_message(message.chat.id, answer)
except:
bot.send_message(message.chat.id,'Ошибка! Город не найден.')
bot.polling( none_stop = True)
input()
Answer the question
In order to leave comments, you need to log in
In new versions of the owm library, you need to use manager to work, and request data through it
owm = pyowm.OWM(OWM_KEY, {'language': 'ru'})
mgr = owm.weather_manager()
observation = mgr.weather_at_place(location)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question