Skip to content

Instantly share code, notes, and snippets.

@omarkdev
Created December 5, 2016 16:57
Show Gist options
  • Save omarkdev/8ae08bf1633eb7fcd6ea77720e90a157 to your computer and use it in GitHub Desktop.
Save omarkdev/8ae08bf1633eb7fcd6ea77720e90a157 to your computer and use it in GitHub Desktop.
import random
import requests,json,sys
class generator:
cpf = []
v1 = 0
v2 = 0
@staticmethod
def generateCpf(self):
for i in range(1, 10):
self.cpf.append(int(random.random()*9))
self.cpf.reverse()
for i in range(9):
self.v1 += int(self.cpf[i])*(9 - (i % 10))
self.v2 += int(self.cpf[i])*(9 - ((i + 1) % 10))
self.v1 = (self.v1 % 11) % 10
self.v2 += self.v1*9
self.v2 = (self.v2 % 11) % 10
self.cpf.reverse()
self.cpf.append(self.v1)
self.cpf.append(self.v2)
return "".join(map(str, self.cpf))
def consultar(cpf):
config = {'api_sus':'http://dabsistemas.saude.gov.br/sistemas/sadab/js/buscar_cpf_dbpessoa.json.php?cpf=', 'cpf': cpf}
req = requests.get(config['api_sus']+config['cpf'])
dados = json.loads(req.content)
if(dados['NO_PESSOA_FISICA'] != "CPF NAO LOCALIZADO"):
print dados['NO_PESSOA_FISICA'], "/", dados['NU_CPF'], "/", dados['DT_NASCIMENTO'], "/", dados['NO_MAE']
for i in range(1, 20):
randomCpf = generator.generateCpf(generator())
consultar(randomCpf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment