V
V
violpeople2021-02-23 13:40:39
Python
violpeople, 2021-02-23 13:40:39

How to attach a database to a Telegram bot?

I ran into a problem, it seems simple, but somehow I can’t enter how to force the bot to use (and most importantly OUTPUT) data from the database. I am using SQLite3

@bot.callback_query_handler(func = lambda call: True)
def callback(call):
      if call.data == 'catalog':
        kb = types.InlineKeyboardMarkup(row_width=2)
        item1 = types.InlineKeyboardButton('Эквадорская роза', callback_data='Ecuador')
        kb.add(item1)
        bot.edit_message_text(chat_id = call.message.chat.id,message_id=call.message.message_id,
    text = 'Выберите категорию товара',reply_markup = kb)
      elif call.data == 'Ecuador':
        kb = types.InlineKeyboardMarkup(row_width=1)
        item2 = types.InlineKeyboardButton('Добавить в корзину',callback_data = 'add_cart')
        item1= types.InlineKeyboardButton('Назад',callback_data='bac')
        kb.add(item2,item1)
        bot.edit_message_text(chat_id = call.message.chat.id,message_id=call.message.message_id,
    text = 'описание цветка',reply_markup=kb)


A piece of the database from which you need to use the values:
import sqlite3 as sq
conn = sq.connect('coc.db')
cur = conn.cursor()

cur.execute("""CREATE TABLE IF NOT EXISTS Ecuador0(position TEXT,price TEXT,image BLOB)""")

Ecuador0= [('Херц  50 см','44,200','image'),
('Хот спот 80 см','50,000','image'),
('Хот Эксплоер 60 см','36,000','image'),
('Хот Эксплоер 70 см','39,600','image'),
('Хот Эксплоер 80 см','44,800','image'),.......

I would really appreciate it if you point me in the right direction :)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wispik, 2021-02-23
@violpeople

study

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question