-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase.py
264 lines (237 loc) · 9.91 KB
/
database.py
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import sqlite3
class DeviceDB():
def __init__(self):
try:
self.conn = sqlite3.connect('database.db')
self.cur = self.conn.cursor()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def create_table(self):
""" Create the table with given columns
"""
try:
self.cur.execute('''CREATE TABLE IF NOT EXISTS device (id int, name text, status text, serial text, app_count int, location text, enabled int)''')
self.conn.commit()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def insert_data(self, entities):
""" Insert records into the table
"""
query = """INSERT INTO device(id, name, status, serial, enabled) VALUES (?,?,?,?,?)"""
try:
self.cur.execute(query, entities)
self.conn.commit()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
# self.conn.close()
def update_device(self, devices):
""" Update the table with given new values"""
try:
ld_list = []
device_list = devices.list_ldplayer()
for key, value in device_list.items():
# print(key, value)
ld_list.append(key)
self.cur.execute("SELECT * FROM device WHERE id = ?", (key,))
result = self.cur.fetchone()
if result is None:
query = """INSERT INTO device(id, name, status, serial, enabled) VALUES (?,?,?,?,?)"""
try:
self.cur.execute(query, (key, value["name"], value["status"], value["serial"], 1))
self.conn.commit()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
else:
self.cur.execute("UPDATE device SET name = ?, status = ?, serial = ?, enabled = ? WHERE id = ?", (value["name"], value["status"], value["serial"], 1, key))
self.conn.commit()
# print(ld_list)
self.cur.execute("SELECT * FROM device")
rows = self.cur.fetchall()
for row in rows:
# print(row[0])
if row[0] not in ld_list:
self.hide_device(row[0])
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def hide_device(self, idx):
self.cur.execute("UPDATE device SET enabled = ? WHERE id = ?", (0, idx))
self.conn.commit()
def select_all(self):
"""Selects all rows from the table to display
"""
try:
self.cur.execute('SELECT id, name, status, serial, app_count, location FROM device WHERE enabled=1')
return self.cur.fetchall()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def delete_record(self):
""" Delete the all record
"""
try:
self.cur.execute("DELETE FROM device")
self.conn.commit()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
class AccountDB():
def __init__(self):
try:
self.conn = sqlite3.connect('database.db')
self.cur = self.conn.cursor()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def create_table(self):
""" Create the table with given columns
"""
try:
#['No', 'Status', 'Device Name', 'Account Name', 'UID', 'Page Name', 'Page ID', 'Password', '2FA', 'Token', 'Cookie', 'Package', 'Location', 'Store', 'Progress']
self.cur.execute('''CREATE TABLE IF NOT EXISTS account (id INTEGER primary key, status text, device int, acct_name text, acct_uid text, page_name text, page_id text, pass text, _2fa text, _token text, cookie text, app_pkg text, location text, store text, progress text)''')
self.conn.commit()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def insert_data(self, entities):
""" Insert records into the table
"""
query = """INSERT INTO account (device, acct_name, acct_uid, pass, _2fa, store) VALUES (?,?,?,?,?,?)"""
try:
self.cur.execute(query, entities)
self.conn.commit()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
# self.conn.close()
def update_data(self, entities):
""" Update the table with given new values"""
try:
self.cur.execute("UPDATE device SET name = ?, status =? WHERE id = ?", entities)
self.conn.commit()
print("The record updated successfully")
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def select_all(self):
"""Selects all rows from the table to display
"""
try:
self.cur.execute('SELECT id, status, device, acct_name, acct_uid, page_name, page_id, pass, _2fa, _token, cookie, app_pkg, location, store, progress FROM account')
return self.cur.fetchall()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def delete_record(self):
""" Delete the all record
"""
try:
self.cur.execute("DELETE FROM account")
self.conn.commit()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
class PageDB():
def __init__(self):
try:
self.conn = sqlite3.connect('database.db')
self.cur = self.conn.cursor()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def create_table(self):
""" Create the table with given columns
"""
try:
self.cur.execute('''CREATE TABLE IF NOT EXISTS page (id int primary key, acct_id int, name text)''')
self.conn.commit()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def insert_data(self, entities):
""" Insert records into the table
"""
query = """INSERT INTO page VALUES (?,?,?)"""
try:
self.cur.execute(query, entities)
self.conn.commit()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
# self.conn.close()
def update_data(self, entities):
""" Update the table with given new values"""
try:
self.cur.execute("UPDATE device SET name = ?, status =? WHERE id = ?", entities)
self.conn.commit()
print("The record updated successfully")
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def select_all(self):
"""Selects all rows from the table to display
"""
try:
self.cur.execute('SELECT * FROM account')
return self.cur.fetchall()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def delate_record(self):
""" Delete the all record
"""
try:
self.cur.execute("DELETE FROM device")
self.conn.commit()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
class Setting():
def __init__(self):
try:
self.conn = sqlite3.connect('database.db')
self.cur = self.conn.cursor()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def create_table(self):
""" Create the table with given columns
"""
try:
self.cur.execute('''CREATE TABLE IF NOT EXISTS setting (name text, value text)''')
self.conn.commit()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def insert_data(self, entities):
""" Insert records into the table
"""
query = """INSERT INTO setting(name, value) VALUES (?,?)"""
try:
name = entities[0]
value = entities[1]
exist_val = self.get_setting(name)
if exist_val:
self.cur.execute("UPDATE setting SET value = ? WHERE name = ?", (value, name,))
self.conn.commit()
else:
self.cur.execute(query, entities)
self.conn.commit()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
# self.conn.close()
def update_data(self, entities):
""" Update the table with given new values"""
try:
self.cur.execute("UPDATE device SET name = ?, status =? WHERE id = ?", entities)
self.conn.commit()
print("The record updated successfully")
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def select_all(self):
"""Selects all rows from the table to display
"""
try:
self.cur.execute('SELECT * FROM setting')
return self.cur.fetchall()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def get_setting(self, param):
"""Selects a row from the table to display
"""
try:
self.cur.execute("SELECT value FROM setting WHERE name = ?", (param,))
return self.cur.fetchone()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)
def delete_record(self):
""" Delete the all record
"""
try:
self.cur.execute("DELETE FROM device")
self.conn.commit()
except sqlite3.IntegrityError as e:
print("Error name:", e.sqlite_errorname)