This commit is contained in:
2024-06-17 10:40:49 +03:00
parent c50fc58257
commit c2255c2166
18 changed files with 1742 additions and 179 deletions

53
database.py Normal file
View File

@@ -0,0 +1,53 @@
import sqlite3
def create_tables():
conn = sqlite3.connect('bot_data.db')
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS orders (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT,
phone TEXT,
address TEXT,
cleaning_time TEXT,
cleaning_type TEXT,
payment_method TEXT
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS users (
user_id INTEGER PRIMARY KEY,
name TEXT,
phone TEXT,
address TEXT
)
''')
conn.commit()
conn.close()
def add_order(name, phone, address, cleaning_time, cleaning_type, payment_method):
conn = sqlite3.connect('bot_data.db')
cursor = conn.cursor()
cursor.execute('''
INSERT INTO orders (name, phone, address, cleaning_time, cleaning_type, payment_method)
VALUES (?, ?, ?, ?, ?, ?)
''', (name, phone, address, cleaning_time, cleaning_type, payment_method))
conn.commit()
conn.close()
def get_order_history(user_id):
conn = sqlite3.connect('bot_data.db')
cursor = conn.cursor()
cursor.execute('''
SELECT * FROM orders WHERE user_id = ?
''', (user_id,))
orders = cursor.fetchall()
conn.close()
return orders