Как сделать так, чтобы бот ждал пока пользователь введет номер задания,и после этого закидывал это значение в переменную per?
def subject(message):
if message.text == 'Русский язык':
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=False)
keyboard.row('Назад')
send = bot.send_message(message.from_user.id, "2 уровень", reply_markup=keyboard)
bot.register_next_step_handler(send, back)
elif message.text == 'Алгебра':
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=False)
keyboard.row('Назад')
send = bot.send_message(message.from_user.id, "2 уровень", reply_markup=keyboard)
bot.register_next_step_handler(send, back)
elif message.text == 'Физика':
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=False)
keyboard.row('Назад')
send = bot.send_message(message.from_user.id, "2 уровень", reply_markup=keyboard)
bot.register_next_step_handler(send, back)
elif message.text == 'Русский язык':
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=False)
keyboard.row('Назад')
send = bot.send_message(message.from_user.id, "text", reply_markup=keyboard)
bot.register_next_step_handler(send, back)
elif message.text == 'Геометрия':
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True, one_time_keyboard=False)
#keyboard.row('Ввести номер задания')
keyboard.row('Назад')
send = bot.send_message(message.from_user.id, "Введите номер задания", reply_markup=keyboard)
bot.register_next_step_handler(send, geom)
elif message.text == 'Домой':
first(message)
def geom(message):
listnum = range(1, 851)
if message.text in listnum:
per = str(message)
URL = 'https://megaresheba.ru/gdz/geometriya/8-klass/merzlyak/' + per + '-nomer'
print(URL)
HEADERS = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36',
'accept': '*/*'}
def get_html(url, params=None):
r = requests.get(url, headers=HEADERS, params=params)
return r
imgg = ''
def get_content(html):
global imgg
soup = BeautifulSoup(html, 'html.parser')
div = soup.find('div', {'class': 'with-overtask'})
imgg = div.find('img')['src']
return imgg
def parse():
html = get_html(URL)
if html.status_code == 200:
get_content(html.text)
return html
parse()
print(imgg)
def back(message):
if message.text == 'Назад':
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
keyboard.add(*[types.KeyboardButton(name) for name in ['Физика', 'Алгебра', 'Русский язык']])
keyboard.add(*[types.KeyboardButton(name) for name in ['нет', 'да']])
keyboard.add(*[types.KeyboardButton(name) for name in ['Домой']])
send = bot.send_message(message.from_user.id, "2 уровень", reply_markup=keyboard)
bot.register_next_step_handler(send, subject)
print('hi')
if __name__ == '__main__':
bot.polling(none_stop=True)