-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpyting.py
175 lines (153 loc) · 5.54 KB
/
pyting.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
import WConio2 as WConio
from colorama import init, Fore, Back, Style
import time
import sys
import os
import random
init(convert=True)
os.system('')
def main():
print(Style.DIM)
print(Fore.YELLOW + '''
█▀█ █▄█ ▀█▀ █ █▄░█ █▀▀
█▀▀ ░█░ ░█░ █ █░▀█ █▄█\n\nTest your Typing skills in the Terminal!!''')
quotes = []
with open('assets/quotes.txt') as f:
x = f.readlines()
quotes.append(x)
print(Style.BRIGHT)
text = random.choice(quotes)
text1 = (text[random.randint(0 , len(text))].replace('\n' , '')).replace('"', '' , 2)
text2 = (text[random.randint(0 , len(text))].replace('\n' , '')).replace('"', '' , 2)
text3 = (text[random.randint(0 , len(text))].replace('\n' , '')).replace('"', '' , 2)
text = text1 + ' ' +text2 + ' ' +text3 #single text is too small
ww = 0
tw = len(text)
cont = False
temp = []
for i in range(-3 , 0):
os.system("title "+f"PyTing {abs(i)}")
print(str(abs(i)) , end='\r')
time.sleep(.8)
os.system("title "+"PyTing - start typing now")
word = len(text.split())
WConio.gotoxy(0, 7)
print(Fore.MAGENTA + text)
WConio.gotoxy(0, 7)
n_text = {}
start = time.time()
i = 0
while True:
try:
key = WConio.getch()
if key[0] == 27:
pass
if key[0] == ord(text[i]):
if text[i] == ' ':
if cont == False:
sys.stdout.write(Fore.GREEN + key[1])
sys.stdout.flush()
if i not in n_text:
n_text[i] = key[0]
i += 1
#cont = False
temp = []
#i += 1
elif cont == False:
sys.stdout.write(Fore.GREEN + key[1])
sys.stdout.flush()
if i not in n_text:
n_text[i] = key[0]
i += 1
else:
sys.stdout.write(Fore.CYAN + key[1])
sys.stdout.flush()
n_text[i] = f'`{key[0]}`'
ww += 1
if i not in n_text:
n_text[i] = key[0]
i += 1
if len(text) == i:
break
elif key[0] == 8 and i != 0 and text[i-1] != ' ':
x = WConio.wherex()
y = WConio.wherey()
WConio.gotoxy(x-1, y)
print(Fore.MAGENTA + text[i-1] , end='')
print(Fore.GREEN , end='')
x = WConio.wherex()
WConio.gotoxy(x-1, y)
try:
temp.remove(i-1)
except:
pass
if i-1 in n_text:
try:
if n_text[i-1].startswith('~'):
cont = False
except:
pass
if temp != []:
cont = True
i -= 1
else:
if key[0] != 8:
if text[i] == ' ':
n_text[i] = '!32!'
ww += 1
"""
if cont == False:
sys.stdout.write(text[i])
sys.stdout.flush()
n_text[i] = '~32~'
ww += 1
#eww += 1
#cont = True
temp.append(i)
i += 1
"""
else:
sys.stdout.write(Fore.RED + text[i])
sys.stdout.flush()
n_text[i] = f'~{key[0]}~'
ww += 1
cont = True
temp.append(i)
i += 1
if len(text) == i:
break
except IndexError:
break
end = time.time()
total_time = end - start
print('\n')
print(Fore.GREEN , end='')
for i in n_text:
if str(n_text[i]).startswith('`'):
x = n_text[i].replace('`', '' , 2)
print(Back.CYAN + chr(int(x)) , end='')
elif str(n_text[i]).startswith('~'):
x = n_text[i].replace('~', '' , 2)
print(Back.RED + chr(int(x)) , end='')
elif str(n_text[i]).startswith('!'):
x = n_text[i].replace('!', '' , 2)
print(Back.BLUE + chr(int(x)) , end='')
else:
print(Fore.GREEN + chr(int(n_text[i])) , end='')
print(Back.RESET , end='')
print()
print(Fore.MAGENTA + f'-->You made {ww} mistake/mistakes')
print(f'-->Accuracy {100 - ((ww/tw)*100)}%')
print(f'-->Your Typing Speed is {word * 60 / total_time} WPM')
if __name__ == '__main__':
os.system("title "+"PyTing")
while True:
x = input(Fore.RED + 'Type \'y\' to start and \'n\' to end [y/n] : ')
if x.lower() == 'y':
WConio.clrscr()
main()
input(Fore.RED + 'press enter to continue ')
WConio.clrscr()
os.system("title "+"PyTing")
else:
break