Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sqlite3
- conn = sqlite3.connect('data/users.db', check_same_thread=False)
- c = conn.cursor()
- #создает таблицу в базе данных
- c.execute("""CREATE TABLE users (
- id integer,
- first_name text,
- last_name text,
- is_admin boolean DEFAULT FALSE,
- is_newsletter boolean DEFAULT FALSE,
- date text
- )""")
- #а вот код, который достает данные из базы данных
- c.execute("""SELECT * FROM users WHERE id='{}'""".format(message.chat.id))
- ans = c.fetchall()
- #вставить в базу данных
- c.execute("""INSERT INTO users VALUES ({id},'{first_name}','{last_name}',
- '{admin}','{newsletter}','{date}')""".format(
- id=message.chat.id,
- first_name=message.chat.first_name,
- last_name=message.chat.last_name,
- admin=0,
- newsletter=0,
- date=datetime.now().strftime("%Y-%m-%d %H:%M:%S")
- ))
- conn.commit()
- #изменить данные в базе данных
- c.execute("""UPDATE users SET is_newsletter = 1 WHERE id = {}""".format(message.chat.id))
- conn.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement