D
D
Danil2021-08-25 18:46:43
Python
Danil, 2021-08-25 18:46:43

What's wrong with Python weather bot in Telegram?

When you write a city to the bot, it only responds with the message: "I can't do much yet, come back later :)" from the penultimate line of code, tell me what I need to do

from pyowm import OWM
from pyowm.utils.config import get_default_config
import telebot

config_dict = get_default_config()
config_dict['language'] = 'ru'

owm = OWM( 'TOKEN', config_dict )
mgr = owm.weather_manager()
bot = telebot.TeleBot("TOKEN")

@bot.message_handler(content_types=['text'])
def answer(message):
    observation = mgr.weather_at_place(message.text)
    w = observation.weather
    temp = w.temperature("celsius")["temp"]

    answer = "В городе " + message.text + " на данный момент " + w.detailed_status + "\n"
    answer += "Температура сейчас в районе " + str(temp) + "\n\n"

    if temp <10:
        answer += "На улице холодновато, пожалуй оденься потеплее"
    elif temp >10:
        answer += "На улице тепло, можно чилить :)"
    else:
        answer += "Хоть в трусах иди!!!!!!"

    bot.send_message(message.chat.id, answer)

bot.send_message(message.chat.id, "Я пока мало чего умею, приходите позже :)")
bot.polling(none_stop = True)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-08-25
@Tw1xqq

1. Wrap the code correctly, don't you have such a mess in the editor?
2. No need to name functions the same as variables
3.

he only responds with a message: "I don't know much yet, come back later :)"
You do not send anything other than sending this message in the code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question