-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscores.py
72 lines (56 loc) · 1.52 KB
/
scores.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
from mysql import connector as msql
from termcolor import colored
def tabulize_scores(record, clr='light_cyan'): #To tabulize and make data segsy
record.sort(key=lambda x:x[1],reverse=True)
l=[]
l1=[]
for i in record:
l.append(i[0])
for i in record:
l1.append(i[1])
s=len(l)
lines=4*8
print(colored('+'+'-'*lines+'+',clr))
print(colored('\033[1m HIGH SCORES !!\033[0m','magenta'))
print(colored('+'+'-'*lines+'+',clr))
for i in range(s):
p=l[i].capitalize()
q=str(l1[i])
print(colored('|'+ str(i+1).center(5)+'|'+ p.center(15)+'|'+q.center(10)+'|',clr))
print(colored('+'+'-'*lines+'+',clr))
def show():
con = msql.connect(
host="localhost",
user="root",
password="surya@2006",
database="score"
)
cursor=con.cursor()
cursor.execute('SELECT * FROM SCORES;')
records=cursor.fetchall()
tabulize_scores(records)
cursor.close()
con.close()
def enter_name(name,score):
con = msql.connect(
host="localhost",
user="root",
password="surya@2006",
database="score"
)
names=[]
cursor=con.cursor()
cursor.execute('SELECT * FROM SCORES;')
records=cursor.fetchall()
# print(records)
for i in records:
names.append(i[0])
# print(names)
if name not in names:
cursor.execute(
'''INSERT INTO SCORES
VALUES ('{}',{});'''.format(name,score)
)
con.commit()
cursor.close()
con.close()