A
A
Alexunkas2020-05-23 13:56:35
SQLite
Alexunkas, 2020-05-23 13:56:35

How to glue sqlite3 and pytelegrambotapi?

Hello everyone, I am learning to build bots using the pytelegrambotapi library.
I described the problem in the undercode, but my hands are itching to figure out how to make it so that the information added from the user is added to the database. and somehow returned back to the user

import telebot

bot = telebot.TeleBot('0000:00000000000000000000)

@bot.message_handler(commands=['start'])
def start_message(message):
    bot.send_message(message.chat.id, 'Привет, введи свой логин')

@bot.message_handler(content_types=['text'])
#На этом моменте я застрял 
bot.polling()


import sqlite3

db = sqlite3.connect('server.db')
sql = db.cursor()

sql.execute("""CREATE TABLE IF NOT EXISTS users (
    login TEXT,
    password TEXT,
    cash BIGINT
)""")

db.commit()
user_login = # Я понимаю что логин равен введённому сообщению юзера но как это собрать?
user_pasword = #Так же само

sql.execute("SELECT login FROM users")
if sql.fetchone() is None:
    sql.execute(f"INSERT INTO users VALUES (?,?,?)",(user_login, user_pasword, 0))
    db.commit()
bot.send_message(message.chat.id,  Добро пожаловать + message.from_user.first_name )
else:
bot.send_message(message.chat.id, 'Данный логин уже зарегистрирован!')
    for value in sql.execute("SELECT * FROM users"):
bot.send_message(message.chat.id, value [0])

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question