Last active
May 6, 2019 03:49
-
-
Save etra0/b5ef3f409d18ab46cb11e83260f7a93a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
from time import time, sleep | |
from random import randint | |
import random as r | |
RUTS = ['19.470.140-3', | |
'20.067.784-k', | |
'10.481.357-7', | |
'11.624.369-5', | |
'15.753.502-1', | |
'19.124.836-8', | |
'19.154.575-5', | |
'15.324.128-k', | |
'17.684.932-5', | |
'12.789.123-0'] | |
def load_ruts(): | |
ruts = [] | |
try: | |
with open('ruts.txt') as f: | |
for line in f: | |
# para omitir comentarios! | |
if "#" in line: | |
continue | |
ruts.append(line.strip()) | |
except: | |
with open('ruts.txt', 'w') as f: | |
f.write("# importante seguir el formato!\n") | |
for rut in RUTS: | |
f.write(rut + '\n') | |
ruts = RUTS | |
while '' in ruts: | |
del ruts[ruts.index('')] | |
return ruts | |
RUTS = load_ruts() | |
def get_random(): | |
return RUTS[randint(0, len(RUTS) - 1)] | |
def generate_rut(): | |
start = '{:,}'.format(randint(1000000, 25000000)).replace(',', '.') | |
end = r.choice(list(map(str, range(0, 10))) + ['k']) | |
return start + '-' + end | |
def limpiar(texto): | |
return texto.replace('.','').replace('-k','10').replace('-','0') | |
if __name__ == "__main__": | |
diff = input('generar rut o conocidos (1 o 2): ') | |
if diff == '1': | |
func = generate_rut | |
else: | |
func = get_random | |
# Cantidad de ruts a ingresar | |
Q = 10 | |
n = Q | |
for i in range(1,4): | |
print(4-i) | |
sleep(1) | |
print("ahora!") | |
choice = func() | |
start = time() | |
while n != 0: | |
print("Escribe '%s'" % choice) | |
t = str(input()) | |
if t.strip() != limpiar(choice): | |
print("\nerror, escribir de nuevo\n") | |
continue | |
else: | |
print("\nfaltan %d veces\n" % (n - 1)) | |
n -= 1 | |
choice = func() | |
end = time() | |
print("Tardaste %f segundos" % (end - start)) | |
user = input('ingresa nombre: ') | |
with open('results.csv', 'a') as f: | |
f.write('{0};{1};{2}\n'.format(user, end - start, Q)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment