C
C
CTPEJIOK432019-10-31 23:51:21
Python
CTPEJIOK43, 2019-10-31 23:51:21

Why doesn't my Telegram weather bot work in python?

I recently started learning Python, made a telegram bot on it using a video lesson, also found a question on the same bot on this site (Toaster) and copied it a bit. I received my weather and bot tokens, entered (where ***), but when I start it on the PC, a lot of incomprehensible errors come out, please help me figure out what's wrong, maybe there are spelling errors? And also tell us how and where it is better to run this bot so that it works without a PC turned on, thanks in advance, I'm waiting for answers ...
Here is the code itself:

import pyowm
import telebot

owm = pyowm.OWM('***', language='ru')
bot = telebot.TeleBot('***')


@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 pyowm.exceptions.api_response_error.NotFoundError:
        bot.send_message(message.chat.id, 'Город не найден!')


bot.polling(none_stop=True)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
C
CTPEJIOK43, 2019-11-01
@CTPEJIOK43

The question is closed, I found a solution, everything was correct in the code, it was only necessary to install a VPN) ;)

L
Loper47, 2019-11-01
@Loper47

If you copied my code, then I would have copied it completely, maybe it would have worked

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question