UnboundLocalError: local variable 't_min' referenced before assignment
def process_select_step(message):
try:
if (message.text == 'Погода'):
msg = bot.send_message(message.from_user.id, "Выберите город (например Москва)")
bot.register_next_step_handler(msg, next_weather_step)
else:
send_welcome(message)
except Exception as e:
bot.reply_to(message, 'ooops!')
print(e)
def next_weather_step(message):
town = message.text
weather(message, towns=town)
# Погода
def weather(message,towns):
r = requests.get('https://sinoptik.ua/погода-{0}'.format(towns))
html = BS(r.content, 'html.parser')
for el in html.select('#content'):
t_min = el.select('.temperature .min')[0].text
print(t_min)
t_max = el.select('.temperature .max')[0].text
print(t_max)
text = el.select('.wDescription .description')[0].text
print(text)
# убрать клавиатуру
markup = types.ReplyKeyboardRemove(selective=False)
bot.send_message(message.from_user.id, "Привет, погода на сегодня:\n",reply_markup=markup)
2020-05-27 16:26:00,818 (util.py:68 WorkerThread2) ERROR - TeleBot: "UnboundLocalError occurred, args=("local variable 't_min' referenced before assignment",) Traceback (most recent call last): File "C:\Users\User\PycharmProjects\Telebot\venv\lib\site-packages\telebot\util.py", line 62, in run task(*args, **kwargs) File "C:/Users/User/PycharmProjects/Telebot/main.py", line 34, in next_weather_step weather(message, towns=town) File "C:/Users/User/PycharmProjects/Telebot/main.py", line 50, in weather t_min + ', ' + t_max + '\n' + text, reply_markup=markup) UnboundLocalError: local variable 't_min' referenced before assignment