python telegram bot multiple choice
I try to launch telegram bot in Python using telebot library. The bot is poll, tha main purpose is to ask respondents and then write their answers to database. I have some questions with multiple choice and have no idea how to make it with writing to DB in parallel. It's my code
import telebot # pip install pyTelegramBotAPI
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton
from create_bd import create_db
bot = telebot.TeleBot('token')
create_db()
from create_bd import add_exercise
markup = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = telebot.types.KeyboardButton("Разработчик")
item2 = telebot.types.KeyboardButton("Тестировщик (QA)")
item3 = telebot.types.KeyboardButton("Project Manager")
item4 = telebot.types.KeyboardButton("Product Manager")
item5 = telebot.types.KeyboardButton("Менеджер по продажам")
item6 = telebot.types.KeyboardButton("Менеджер по развитию/BDM")
item7 = telebot.types.KeyboardButton("Системный аналитик")
item8 = telebot.types.KeyboardButton("Иное")
item9 = telebot.types.KeyboardButton("STOP")
markup.add(item1, item2, item3, item4, item5, item6, item7, item8, item9)
@bot.message_handler(commands=['start'])
def q1(message):
markup = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = telebot.types.KeyboardButton("мужской")
item2 = telebot.types.KeyboardButton("женский")
markup.add(item1, item2)
a=bot.send_message(message.chat.id,'Укажите ваш пол', reply_markup=markup)
bot.register_next_step_handler(a, q2)
def q2 (message):
add_exercise([message.chat.id,'gender', 'Укажите ваш пол', message.text])
aa=bot.send_message(message.chat.id,'Укажите вашу специализацию', reply_markup=markup)
bot.register_next_step_handler(aa, q3)
markuppro = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True)
i1 = telebot.types.KeyboardButton("Backend")
i2 = telebot.types.KeyboardButton("Frontend")
i3 = telebot.types.KeyboardButton("Fullstack")
i4 = telebot.types.KeyboardButton("Mobile")
i5 = telebot.types.KeyboardButton("Desktop")
i6 = telebot.types.KeyboardButton("Gamedev")
i7 = telebot.types.KeyboardButton("Embedded")
i8 = telebot.types.KeyboardButton("STOP")
markuppro.add(i1, i2, i3, i4, i5, i6, i7,i8)
def q3 (message):
if message.text=='Разработчик':
aa=bot.send_message(message.chat.id, 'Какой именно разработчик?', reply_markup=markuppro)
bot.register_next_step_handler(aa, q3pro)
else:
add_exercise([message.chat.id, 'specialisation', 'Укажите вашу специализацию', message.text])
markup = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = telebot.types.KeyboardButton("<25")
item2 = telebot.types.KeyboardButton("25-35")
item3 = telebot.types.KeyboardButton("35-45")
item4 = telebot.types.KeyboardButton("45 и выше")
markup.add(item1, item2, item3, item4)
bot.send_message(message.chat.id, 'Укажите ваш возраст', reply_markup=markup)
def q3pro(message):
add_exercise([message.chat.id, 'specialisation', 'Укажите вашу специализацию', message.text + ' разработчик'])
markup1 = telebot.types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = telebot.types.KeyboardButton("<25")
item2 = telebot.types.KeyboardButton("25-35")
item3 = telebot.types.KeyboardButton("35-45")
item4 = telebot.types.KeyboardButton("45 и выше")
markup1.add(item1, item2,item3,item4)
bot.send_message(message.chat.id,'Укажите ваш возраст', reply_markup=markup1)
@bot.message_handler()
def get(message):
add_exercise([message.chat.id,'age','Укажите ваш возраст', message.text])
print('OK')
bot.polling(none_stop=True, interval=0)