query = f"SELECT product_name, product_price, product_description, product_picture FROM Accessories WHERE id>=1 and user_id != {message.from_user.id}"
cursor.execute(query)
result = cursor.fetchall()
if result:
for row in result:
product_name, product_price, product_description, product_picture = row
if product_picture:
product_picture = product_picture.strip()
padding = len(product_picture) % 4
product_picture += '=' * padding
try:
image_data = base64.b64decode(product_picture)
image_file = io.BytesIO(image_data)
image_file.seek(0)
bot.send_photo(message.chat.id, image_file,
caption=f"Name: {product_name}, Price: {product_price}, Description: {product_description}")
except Exception as e:
print("Error sending photo:", e)
else:
if all([product_name, product_price, product_description]):
response_message = f"Name: {product_name}, Price: {product_price}, Description: {product_description}"
bot.send_message(message.chat.id, response_message)
else:
continue
else:
bot.send_message(message.chat.id, "No data")
bot.register_next_step_handler(message, handle_skip)