Repository navigation
Expand file tree
/
Copy pathquery.py
More file actions
132 lines (118 loc) · 4.49 KB
/
Copy pathquery.py
File metadata and controls
132 lines (118 loc) · 4.49 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import sqlite3
from config import DB_NAME
def insert(data):
try:
sqlite_connection = sqlite3.connect(DB_NAME)
cursor = sqlite_connection.cursor()
print("INS: Подключен к БД")
sqlite_insert_query = data
cursor.execute(sqlite_insert_query)
sqlite_connection.commit()
print(f"Запись успешно вставлена в таблицу {DB_NAME}")
cursor.close()
return cursor.lastrowid
except sqlite3.Error as error:
print("INS: Ошибка при работе с БД", error)
finally:
if sqlite_connection:
sqlite_connection.close()
print("INS: Соединение с БД закрыто")
def delete(id):
try:
sqlite_connection = sqlite3.connect(DB_NAME)
cursor = sqlite_connection.cursor()
print("DEL: Подключен к БД")
sqlite_delete_query = f"""DELETE FROM contacts WHERE id='{id}'"""
cursor.execute(sqlite_delete_query)
sqlite_connection.commit()
print(f"Запись удалена из таблицы {DB_NAME}")
cursor.close()
return cursor.lastrowid
except sqlite3.Error as error:
print("DEL: Ошибка при работе с БД", error)
finally:
if sqlite_connection:
sqlite_connection.close()
print("DEL: Соединение с БД закрыто")
def out(data):
try:
sqlite_connection = sqlite3.connect(DB_NAME)
cursor = sqlite_connection.cursor()
print("OUT: Подключен к БД")
sqlite_select_query = data
cursor.execute(sqlite_select_query)
records = cursor.fetchall()
cursor.close()
return records
except sqlite3.Error as error:
print("OUT: Ошибка при работе с БД", error)
finally:
if sqlite_connection:
sqlite_connection.close()
print("OUT: Соединение с БД закрыто")
def out_all_id():
try:
sqlite_connection = sqlite3.connect(DB_NAME)
cursor = sqlite_connection.cursor()
print("OUT: Подключен к БД")
sqlite_select_query = """SELECT id FROM contacts"""
cursor.execute(sqlite_select_query)
records = cursor.fetchall()
cursor.close()
return records
except sqlite3.Error as error:
print("OUT: Ошибка при работе с БД", error)
finally:
if sqlite_connection:
sqlite_connection.close()
print("OUT: Соединение с БД закрыто")
def out_all_open():
try:
sqlite_connection = sqlite3.connect(DB_NAME)
cursor = sqlite_connection.cursor()
print("OUT: Подключен к БД")
sqlite_select_query = """SELECT id FROM contacts WHERE status='Open'"""
cursor.execute(sqlite_select_query)
records = cursor.fetchall()
cursor.close()
return records
except sqlite3.Error as error:
print("OUT: Ошибка при работе с БД", error)
finally:
if sqlite_connection:
sqlite_connection.close()
print("OUT: Соединение с БД закрыто")
def get_ids():
try:
sqlite_connection = sqlite3.connect(DB_NAME)
cursor = sqlite_connection.cursor()
print("OUT: Подключен к БД")
sqlite_select_query = """SELECT id FROM tg_authorized"""
cursor.execute(sqlite_select_query)
records = cursor.fetchall()
cursor.close()
return records
except sqlite3.Error as error:
print("OUT: Ошибка при работе с БД", error)
finally:
if sqlite_connection:
sqlite_connection.close()
print("OUT: Соединение с БД закрыто")
def auth(id):
try:
sqlite_connection = sqlite3.connect(DB_NAME)
cursor = sqlite_connection.cursor()
print("AUTH: Подключен к БД")
sqlite_select_query = """SELECT id FROM tg_authorized"""
cursor.execute(sqlite_select_query)
records = cursor.fetchall()
cursor.close()
for i in records:
if i[0] == id:
return True
except sqlite3.Error as error:
print("AUTH: Ошибка при работе с БД", error)
finally:
if sqlite_connection:
sqlite_connection.close()
print("AUTH: Соединение с БД закрыто")