-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaderboard.py
315 lines (302 loc) · 13.8 KB
/
leaderboard.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
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
# Copyright (C) [2023] [Mohammad Dorri] <[https://www.github.com/PG6AW]>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from tkinter import messagebox
import getpass
import sqlite3
import shutil
import os
import subprocess
# Copyright (C) 2023 Mohammad Dorri https://www.github.com/PG6AW
current_username = getpass.getuser()
event_by_admin = current_username
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
the_user = "*N-U-L-L*"
try:
conn2 = sqlite3.connect("accounts.db")
cursor2 = conn2.cursor()
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
cursor2.execute("SELECT id FROM login_logs WHERE event_by_admin=?", (event_by_admin,))
Ids = cursor2.fetchall()
if Ids is None:
Ids = str(Ids)
ids = max(Ids)
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
for Id in ids:
Id = int(Id)
cursor2.execute("SELECT username FROM login_logs WHERE id=?", (Id,))
user_name = cursor2.fetchone()
if user_name is None:
user_name = str(user_name)
else:
for the_user in user_name:
the_user = str(the_user)
conn2.close()
except (sqlite3.OperationalError , ValueError , sqlite3.ProgrammingError):
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
pass
if the_user == "LOGGED->OUT" or the_user == "*N-U-L-L*":
retry = True
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
while retry:
retry = messagebox.askretrycancel("LOGGED OUT!", "You are currently Logged Out!\n\nYOU'D BE BETTER OFF CANCELLING THIS & LOG-IN FIRST BEFORE YOU COME BACK & RETRY!")
subprocess.Popen(['python', 'login.py'])
exit()
else:
pass
conn3 = sqlite3.connect("typewriter.db")
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
cursor3 = conn3.cursor()
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
cursor3.execute("""CREATE TABLE IF NOT EXISTS records (
record_id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT,
total_score INTEGER,
net_wpm TEXT,
gross_wpm TEXT,
pure_wpm TEXT,
accuracy TEXT,
correct_chars INTEGER,
total_keystrokes INTEGER,
correct_keystrokes INTEGER,
incorrect_keystrokes INTEGER,
time_in_minutes INTEGER,
extended_seconds INTEGER,
total_minutes TEXT,
typed_words INTEGER,
correct_words INTEGER,
incorrect_words INTEGER,
positive_points INTEGER,
negative_points INTEGER,
all_keypress INTEGER,
interrupted TEXT,
idle TEXT,
challenge_mode TEXT,
typewriter_mode TEXT,
net_cpm TEXT,
kpm TEXT,
kph INTEGER,
keyboard_layout TEXT,
keyboard_keys_used INTEGER,
keyboard_keys TEXT,
os_name TEXT,
os_admin TEXT,
event_date TEXT
)""")
conn3.commit()
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
class leaderboard_app:
def directory_mananager():
directory = 'leaderboard_cache'
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
if not os.path.exists(directory):
os.makedirs(directory)
else:
pass
def delete_copy_rename_paste(source_dir, destination_dir, file_name, new_file_name):
source_path = os.path.join(source_dir, file_name)
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
destination_path = os.path.join(destination_dir, new_file_name)
try:
os.remove(destination_path)
except FileNotFoundError:
pass
try:
shutil.copy2(source_path, destination_path)
except FileNotFoundError:
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
pass
source_directory = ''
destination_directory = 'leaderboard_cache'
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
file_to_copy = 'typewriter.db'
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
new_file_name = 'typewriter.db'
delete_copy_rename_paste(source_directory, destination_directory, file_to_copy, new_file_name)
def delete_record(destination_dir, new_file_name):
destination_path = os.path.join(destination_dir, new_file_name)
try:
os.remove(destination_path)
except FileNotFoundError:
pass
destination_directory = ''
new_file_name = 'leaderboard.db'
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
delete_record(destination_directory, new_file_name)
def db_manager():
global conn4 , conn5
conn4 = sqlite3.connect("leaderboard_cache/typewriter.db")
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
cursor4 = conn4.cursor()
cursor4.execute("""CREATE TABLE IF NOT EXISTS records (
record_id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT,
total_score INTEGER,
net_wpm TEXT,
gross_wpm TEXT,
pure_wpm TEXT,
accuracy TEXT,
correct_chars INTEGER,
total_keystrokes INTEGER,
correct_keystrokes INTEGER,
incorrect_keystrokes INTEGER,
time_in_minutes INTEGER,
extended_seconds INTEGER,
total_minutes TEXT,
typed_words INTEGER,
correct_words INTEGER,
incorrect_words INTEGER,
positive_points INTEGER,
negative_points INTEGER,
all_keypress INTEGER,
interrupted TEXT,
idle TEXT,
challenge_mode TEXT,
typewriter_mode TEXT,
net_cpm TEXT,
kpm TEXT,
kph INTEGER,
keyboard_layout TEXT,
keyboard_keys_used INTEGER,
keyboard_keys TEXT,
os_name TEXT,
os_admin TEXT,
event_date TEXT
)""")
conn4.commit()
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
conn5 = sqlite3.connect("leaderboard.db")
cursor5 = conn5.cursor()
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
cursor5.execute("""CREATE TABLE IF NOT EXISTS realtime_records (
position INTEGER PRIMARY KEY AUTOINCREMENT,
record_id INTEGER,
username TEXT,
total_score INTEGER,
net_wpm TEXT,
gross_wpm TEXT,
pure_wpm TEXT,
accuracy TEXT,
correct_chars INTEGER,
total_keystrokes INTEGER,
correct_keystrokes INTEGER,
incorrect_keystrokes INTEGER,
time_in_minutes INTEGER,
extended_seconds INTEGER,
total_minutes TEXT,
typed_words INTEGER,
correct_words INTEGER,
incorrect_words INTEGER,
positive_points INTEGER,
negative_points INTEGER,
all_keypress INTEGER,
interrupted TEXT,
idle TEXT,
challenge_mode TEXT,
typewriter_mode TEXT,
net_cpm TEXT,
kpm TEXT,
kph INTEGER,
keyboard_layout TEXT,
keyboard_keys_used INTEGER,
keyboard_keys TEXT,
os_name TEXT,
os_admin TEXT,
event_date TEXT
)""")
conn5.commit()
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
cursor5.execute("DELETE FROM realtime_records")
conn5.commit()
def db_slicer():
conn4 = sqlite3.connect("leaderboard_cache/typewriter.db")
cursor4 = conn4.cursor()
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
conn5 = sqlite3.connect("leaderboard.db")
cursor5 = conn5.cursor()
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
records_count = 1
while records_count != 0:
cursor4.execute("SELECT total_score FROM records")
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
total_scores = cursor4.fetchall()
if total_scores is None:
records_count = 0
return
else:
records_count = len(total_scores)
try:
total = max(total_scores)
except ValueError:
return
for scores in total:
score = int(scores)
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
cursor4.execute("SELECT username FROM records WHERE total_score=?", (score,))
username = cursor4.fetchone()
for user in username:
the_username = str(user)
cursor4.execute("SELECT record_id, total_score, net_wpm, gross_wpm, pure_wpm, accuracy, correct_chars, total_keystrokes, correct_keystrokes, incorrect_keystrokes, time_in_minutes, extended_seconds, total_minutes, typed_words, correct_words, incorrect_words, positive_points, negative_points, all_keypress, interrupted, idle, challenge_mode, typewriter_mode, net_cpm, kpm, kph, keyboard_layout, keyboard_keys_used, keyboard_keys, os_name, os_admin, event_date FROM records WHERE username=? and total_score=?", (the_username, score))
record_set = cursor4.fetchall()
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
records_list = []
for i in record_set[0]:
records_list.append(i)
record_set = []
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
record_set = records_list
cursor5.execute("INSERT INTO realtime_records (record_id, username, total_score, net_wpm, gross_wpm, pure_wpm, accuracy, correct_chars, total_keystrokes, correct_keystrokes, incorrect_keystrokes, time_in_minutes, extended_seconds, total_minutes, typed_words, correct_words, incorrect_words, positive_points, negative_points, all_keypress, interrupted, idle, challenge_mode, typewriter_mode, net_cpm, kpm, kph, keyboard_layout, keyboard_keys_used, keyboard_keys, os_name, os_admin, event_date) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (record_set[0], the_username, record_set[1], record_set[2], record_set[3], record_set[4], record_set[5], record_set[6], record_set[7], record_set[8], record_set[9], record_set[10], record_set[11], record_set[12], record_set[13], record_set[14], record_set[15], record_set[16], record_set[17], record_set[18], record_set[19], record_set[20], record_set[21], record_set[22], record_set[23], record_set[24], record_set[25], record_set[26], record_set[27], record_set[28], record_set[29], record_set[30], str(record_set[31])))
conn5.commit()
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
cursor4.execute("DELETE FROM records WHERE username=?", (the_username,))
conn4.commit()
def purger():
subprocess.Popen(['python', 'helper/helper.py'])
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
leaderboard_app.directory_mananager()
leaderboard_app.db_manager()
leaderboard_app.db_slicer()
leaderboard_app.purger()
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
conn3.close()
conn4.close()
conn5.close()
# Copyright (C) [2023] [Mohammad Dorri]
# https://www.github.com/PG6AW
subprocess.Popen(['python', 'leaderboard_gui.py'])
exit()