исправь некоторые участки кода import logging import sqlite3 import telegram from…
- User
исправь некоторые участки кода import logging import sqlite3 import telegram from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update from telegram.ext import Updater, CommandHandler, CallbackQueryHandler, CallbackContext
logging.basicConfig(level=logging.INFO) bot = telegram.Bot(token='YOUR_BOT_TOKEN') API_TOKEN = 'YOUR_API_TOKEN'
category_tables = { 'Кроссовки': 'items', 'Верхняя одежда': 'items1', 'Аксессуары': 'items2', }
def start(update: Update, context: CallbackContext): keyboard = [ [InlineKeyboardButton(category, callback_data=category) for category in category_tables] ] reply_markup = InlineKeyboardMarkup(keyboard) if update.message: update.message.reply_text('Выберите категорию товара:', reply_markup=reply_markup) else: query = update.callback_query query.answer() query.edit_message_text('Выберите категорию товара:', reply_markup=reply_markup)
def category_handler(update: Update, context: CallbackContext): query = update.callback_query category = query.data table = category_tables[category] conn = sqlite3.connect('kross.db') c = conn.cursor() c.execute(f'SELECT name FROM {table}') items = c.fetchall() keyboard = [ [InlineKeyboardButton(items[i][0], callback_data=f'{table}{i}') for i in range(min(4, len(items)))] ] if len(items) > 4: keyboard.append([ InlineKeyboardButton('Вперед', callback_data=f'next{table}0_4') ]) reply_markup = InlineKeyboardMarkup(keyboard) query.answer() query.edit_message_text(f'Выберите товар ({category}):', reply_markup=reply_markup)
def show_product(update: Update, context: CallbackContext): query = update.callback_query data = query.data.split(' ') table = data[0] index = int(data[1]) conn = sqlite3.connect('kross.db') c = conn.cursor() c.execute(f'SELECT name, size, info, price, photo_link FROM {table}') items = c.fetchall() item = items[index] text = f'Название: {item[0]}\nРазмер: {item[1]}\nОписание: {item[2]}\nЦена: {item[3]}\nСсылка на фото: {item[4]}' keyboard = [ [InlineKeyboardButton('Вернуться', callback_data=f'back_{table}')] ] reply_markup = InlineKeyboardMarkup(keyboard) query.answer() query.edit_message_text(text=text, reply_markup=reply_markup)
def change_page(update: Update, context: CallbackContext): query = update.callback_query data = query.data.split(' ') action = data[0] table = data[1] start_index = int(data[2]) end_index = int(data[3]) conn = sqlite3.connect('kross.db') c = conn.cursor() c.execute(f'SELECT name FROM {table}') items = c.fetchall() prev_start = max(0, start_index - 4) prev_end = start_index next_start = end_index next_end = min(end_index + 4, len(items)) if action == 'next': start_index = next_start end_index = next_end def show_product(update: Update, context: CallbackContext): query = update.callback_query data = query.data.split(‘‘) table = data[0] index = int(data[1])
conn = sqlite3.connect(‘kross.db’) c = conn.cursor() c.execute(f’SELECT name, size, info, price, photo_link FROM {table}’) items = c.fetchall() item = items[index] text = f’Название: {item[0]}\nРазмер: {item[1]}\nОписание: {item[2]}\nЦена: {item[3]}\nСсылка на фото: {item[4]}‘ keyboard = [ [InlineKeyboardButton(‘Вернуться’, callback_data=f’back_{table}’)] ] reply_markup = InlineKeyboardMarkup(keyboard) query.answer() query.edit_message_text(text=text, reply_markup=reply_markup) - Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.