Answer the question
In order to leave comments, you need to log in
How to make the user enter the city in which to find the weather?
import telebot
import random
import datetime
import pyowm
from pyowm import OWM
from pyowm.utils.config import get_default_config
from telebot import types
config_dict = get_default_config()
config_dict['language'] = 'ru'
owm = OWM('c6541024768a61e8b09f01e0c656430d', ) # token weather
mgr = owm.weather_manager()
place = 'Dnepr'
observation = mgr.weather_at_place(place)
w = observation.weather
temp = w.temperature('celsius')['temp']
bot = telebot.TeleBot('1466558022: AAHMU0GWy62ncZF5KZqa9iL6q-dWu28vAq4')
@bot.message_handler(commands=['start'])
def start_message(message):
welcome_sticker = open('welcome.webp', 'rb')
bot.send_sticker(message.chat.id, welcome_sticker)
bot.send_message(message.chat.id, 'Come in don't be afraid, come out don't cry...', reply_markup =markup)
@bot.message_handler(content_types=['text'])
def calendar(message):
weather(message)
randomnum(message)
##code not needed
@bot.message_handler(commands=['/weather'])
def weather(message):
try:
bot.send_message(message.chat.id, 'In the city ' + place + ' ' + (
str(w.temperature('celsius')['temp']) + ' Celsius degrees' + '\n'))
bot.send_message(message.chat.id, 'Outside ' + str(w.detailed_status), reply_markup=markup)
except pyowm.commons.exceptions.NotFoundError:
bot.send_message(message.chat.id, 'City not found:(',reply_markup=markup)
def namebase(message):
## code not needed
def randomnum(message):
## code not needed
bot.polling() # Makes the bot work and wait for the command
\
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question