Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import os
- import time
- def geradorDeCPF():
- def criaCPF():
- cpf = []
- for i in range(9):
- k = random.randint(0, 9)
- cpf.append(k)
- return cpf
- def digitoVerificador(cpf):
- for i in range(2):
- d = 0
- if len(cpf) == 9:
- g = 10
- k = 9
- elif len(cpf) == 10:
- g = 11
- k = 10
- for i in range(k):
- d += g * cpf[i]
- g -= 1
- d = d % 11
- if d < 2:
- d = 0
- else:
- d = 11 - d
- cpf.append(d)
- def formatarCPF(cpf):
- cpf.insert(3, ".")
- cpf.insert(7, ".")
- cpf.insert(11, "-")
- cpf.insert(14, "\n")
- def exibir(cpf):
- os.system("clear")
- print("\nÚltimo CPF: ", end='')
- for i in cpf:
- print(i, end='')
- print()
- def gerador():
- cpf = criaCPF()
- digitoVerificador(cpf)
- formatarCPF(cpf)
- exibir(cpf)
- for i in cpf:
- p = str(i)
- arq.write(p)
- nome = "CPF"
- nome = str(input("Digite um nome para o arquivo:\nPadrão: CPF.txt\n>>> "))
- if ".txt" not in nome:
- nome = nome + ".txt"
- diretorio = "/storage/emulated/0/" + nome
- diretorio = str(input(f"Onde deseja salvar?\nPadrão: {diretorio[:20]}\nDigite espaço para manter o padrão\n>>> "))
- if " " in diretorio:
- diretorio = "/storage/emulated/0/" + nome
- quantidade = int(input("Quantos CPFs deseja gerar?\n>>> "))
- arq = open(diretorio, "w")
- tempo = time.time()
- contador = 0
- for i in range(quantidade):
- os.system("clear")
- gerador()
- porcentagem = quantidade * (i / 100)
- print("{} CPFs gerados.".format(contador + 1))
- k = time.time() - tempo
- print("Tempo de execução: {:.2f}".format(k), end='\r')
- contador += 1
- arq.close()
- print(f"Salvo em: {diretorio}")
- print("Tempo decorrido: {:.2f} segundos".format(k))
- geradorDeCPF()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement