def search(message):
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
keyboard.add(*[types.KeyboardButton(name) for name in ['Еще', 'Остановить']])
bot.send_message(message.chat.id, "Сейчас поищем!", reply_markup=keyboard)
count = 0
sendannk(message,count)
def sendannk(message,count):
try:
ids = '12345678'
with sq.connect('DATABASE.db') as con:
cur = con.cursor()
cur.execute('''SELECT city FROM users WHERE userid = ?''', (ids,))
datacit = cur.fetchall()
datacit = datacit[0][0] ##город юзера
cur.execute('''SELECT rowid FROM users WHERE city = ? ''', (datacit,))
usersrowid = cur.fetchall()
lst = [] #rowid анкет по городу
for s in usersrowid:
sstr = str(s)
sssr = sstr.replace(')','').replace('(','').replace(',','')
lst.append(sssr)
cont = len(lst)
rowidus = lst[count]
with sq.connect('DATABASE.db') as con:
cur = con.cursor()
cur.execute('''SELECT name,old,city,photo,descr,cont FROM users WHERE rowid = ? ''',(rowidus,))
data = cur.fetchall()
dbdata = data[0]
usercity = dbdata[0]
username = dbdata[1]
userold = dbdata[2]
userphoto = dbdata[3]
userdescr = dbdata[4]
usercont = dbdata[5]
caption = username + ', ' + userold + ', ' + usercity + '\n' + userdescr + '\n' + usercont
bot.send_photo(message.chat.id, userphoto, caption)
if message.text == 'Еще':
count += 1
sendannk(message,count)
except:
bot.send_message(message.chat.id, 'Анкеты кончились')
start_message(message)
if message.text == 'Еще':
register_next_step_handler
@bot.message_handler(commands=['search'])
def start_search(message):
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
keyboard.add(*[types.KeyboardButton(name) for name in ['Еще', 'Остановить']])
bot.send_message(message.chat.id, "Сейчас поищем!", reply_markup=keyboard)
sendannk(message, 0)
def sendannk(message, count):
if message.text == 'Остановить':
print('stop')
elif message.text == 'Еще' or count == 0: # Вместо count == 0 можно указать начальное сообщение, чтоб первый раз функция выполнилась, а не по колбэку, в этом случае было бы message.text == '/search', не увидил ничего криминального в каунт = 0 поэтому пусть будет
try:
ids = '12345678'
with sq.connect('DATABASE.db') as con:
cur = con.cursor()
cur.execute('''SELECT city FROM users WHERE userid = ?''', (ids,))
datacit = cur.fetchall()
datacit = datacit[0][0] ##город юзера
cur.execute('''SELECT rowid FROM users WHERE city = ? ''', (datacit,))
usersrowid = cur.fetchall()
lst = [] #rowid анкет по городу
for s in usersrowid:
sstr = str(s)
sssr = sstr.replace(')','').replace('(','').replace(',','')
lst.append(sssr)
cont = len(lst)
rowidus = lst[count]
with sq.connect('DATABASE.db') as con:
cur = con.cursor()
cur.execute('''SELECT name,old,city,photo,descr,cont FROM users WHERE rowid = ? ''',(rowidus,))
data = cur.fetchall()
dbdata = data[0]
usercity = dbdata[0]
username = dbdata[1]
userold = dbdata[2]
userphoto = dbdata[3]
userdescr = dbdata[4]
usercont = dbdata[5]
caption = username + ', ' + userold + ', ' + usercity + '\n' + userdescr + '\n' + usercont
bot.send_photo(message.chat.id, userphoto, caption)
count += 1
msg = bot.send_message(message.chat.id, "Искать еще?")
bot.register_next_step_handler(msg, sendannk, count)
except:
bot.send_message(message.chat.id, 'Анкеты кончились')
start_message(message)
@bot.message_handler(commands=['search'])
def start_search(message):
keyboard = types.ReplyKeyboardMarkup(resize_keyboard=True)
keyboard.add(*[types.KeyboardButton(name) for name in ['Еще', 'Остановить']])
bot.send_message(message.chat.id, "Сейчас поищем!", reply_markup=keyboard)
sendannk(message, 0)
def step_handler(message, count=0):
if message.text == 'Еще':
sendannk(message, count)
elif message.text == 'Остановить':
print('stop')
def sendannk(message, count):
try:
ids = '12345678'
with sq.connect('DATABASE.db') as con:
cur = con.cursor()
cur.execute('''SELECT city FROM users WHERE userid = ?''', (ids,))
datacit = cur.fetchall()
datacit = datacit[0][0] ##город юзера
cur.execute('''SELECT rowid FROM users WHERE city = ? ''', (datacit,))
usersrowid = cur.fetchall()
lst = [] #rowid анкет по городу
for s in usersrowid:
sstr = str(s)
sssr = sstr.replace(')','').replace('(','').replace(',','')
lst.append(sssr)
cont = len(lst)
rowidus = lst[count]
with sq.connect('DATABASE.db') as con:
cur = con.cursor()
cur.execute('''SELECT name,old,city,photo,descr,cont FROM users WHERE rowid = ? ''',(rowidus,))
data = cur.fetchall()
dbdata = data[0]
usercity = dbdata[0]
username = dbdata[1]
userold = dbdata[2]
userphoto = dbdata[3]
userdescr = dbdata[4]
usercont = dbdata[5]
caption = username + ', ' + userold + ', ' + usercity + '\n' + userdescr + '\n' + usercont
bot.send_photo(message.chat.id, userphoto, caption)
count += 1
msg = bot.send_message(message.chat.id, "Искать еще?")
bot.register_next_step_handler(msg, step_handler, count)
except:
bot.send_message(message.chat.id, 'Анкеты кончились')
start_message(message)