-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdatabase.py
More file actions
69 lines (51 loc) · 2.57 KB
/
database.py
File metadata and controls
69 lines (51 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import sqlite3
connect = sqlite3.connect("bot_data.db")
cursor = connect.cursor()
cursor.execute(
"CREATE TABLE IF NOT EXISTS users_table(user_id INTEGER PRIMARY KEY UNIQUE, full_name TEXT, joined_date TEXT)")
cursor.execute("CREATE TABLE IF NOT EXISTS kitoblar(path TEXT)")
cursor.execute(
"CREATE TABLE IF NOT EXISTS user_full_data(ism TEXT NULL, tg_id TEXT UNIQUE NULL,phone_number TEXT NULL,joined_data TEXT NULL)")
cursor.execute("""CREATE TABLE IF NOT EXISTS payments_data(ism TEXT NULL, tg_id TEXT NULL, transaction_id TEXT UNIQUE NULL, summa TEXT DEFAULT "100.000", joined_date datetime NULL, lefted_date datetime NULL, status_joined BOOLEAN DEFAULT 1)""")
async def add_payment_data(ism,tg_id,transaction_id,joined_date,lefted_date):
cursor.execute("INSERT INTO payments_data (ism,tg_id,transaction_id,joined_date,lefted_date) VALUES (?, ?, ?, ?, ?)",(ism,tg_id,transaction_id,joined_date,lefted_date))
connect.commit()
async def get_expired_users(current_date):
cursor.execute("SELECT tg_id FROM payments_data WHERE lefted_date <= ? AND status_joined == 1",(current_date,))
expired_users = cursor.fetchall()
return [user[0] for user in expired_users]
async def update_payment_data(tg_id):
cursor.execute("UPDATE payments_data SET status_joined = 0 WHERE tg_id = ?",(tg_id,))
connect.commit()
async def check_user_data(tg_id):
cursor.execute('SELECT * FROM user_full_data WHERE tg_id=?', (tg_id,))
if cursor.fetchone():
return True
else:
return False
async def get_name_user(tg_id):
cursor.execute('SELECT ism FROM user_full_data WHERE tg_id=?', (tg_id,))
result = cursor.fetchone()
if result:
return result[0]
return None
async def bazaga_qoshish(ism, tg_id, joined_data):
cursor.execute('SELECT * FROM user_full_data WHERE tg_id=?', (tg_id,))
if cursor.fetchone():
return True
else:
cursor.execute("INSERT INTO user_full_data (ism, tg_id, joined_data) VALUES (?, ?, ?)",
(ism, tg_id, joined_data))
connect.commit()
return f"{ism} siz ro`yxatdan o`tdingiz\ntelefon raqamingizni pastdagi tugma orqali jo`nating"
async def update_contact(tg_id, phone_number):
cursor.execute('SELECT * FROM user_full_data WHERE tg_id=?', (tg_id,))
if cursor.fetchone():
cursor.execute('UPDATE user_full_data SET phone_number=? WHERE tg_id=?', (phone_number, tg_id))
connect.commit()
return True
else:
return False
def get_all_data():
cursor.execute('SELECT * FROM user_full_data')
return cursor.fetchall()