db = Database('db.db')
bot = telebot.TeleBot(TOKEN)
class Database:
def __init__(self, database_file):
self.connection = sqlite3.connect(database_file, check_same_thread = False)
self.cursor = self.connection.cursor()
def set_gender(self, chat_id, gender):
with self.connection:
user = self.cursor.execute("SELECT * FROM `users` WHERE `chat_id` = ?", (chat_id,)).fetchmany(1)
if bool(len(user)) == False:
self.cursor.execute("INSERT INTO `users` (`chat_id`, `gender`) VALUES (?,?)", (chat_id, gender))
return True
else:
return False
Файл db.db создан и в нем есть users