-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculos_validacao.py
58 lines (48 loc) · 1.49 KB
/
calculos_validacao.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
def calculo_penutimo_num(cnpj_analize):
algoritimo_calc = [5,4,3,2,9,8,7,6,5,4,3,2]
mult_calc = []
for x, y in enumerate(cnpj_analize):
y = int(y)
mult_calc.append(algoritimo_calc[x] * y)
soma_calculos = sum(mult_calc)
fomula = 11 - (soma_calculos % 11)
if fomula <= 9:
return f'{fomula}'
else:
return '0'
##############################################
def calculo_ultimo_num(cnpj_analize):
algoritimo_calc = [6,5,4,3,2,9,8,7,6,5,4,3,2]
mult_calc = []
for x, y in enumerate(cnpj_analize):
y = int(y)
mult_calc.append(algoritimo_calc[x] * y)
soma_calculos = sum(mult_calc)
fomula = 11 - (soma_calculos % 11)
if fomula <= 9:
return f'{fomula}'
else:
return '0'
##############################################
def montar_estrutura_cnpj(cnpj_analize):
comparando = ''
for n in cnpj_analize:
if len(comparando) in [2,6]:
comparando += '.'
comparando += n
elif len(comparando) == 10:
comparando += '/'
comparando += n
elif len(comparando) == 15:
comparando += '-'
comparando += n
else:
comparando += n
return comparando
##############################################
def so_numeros(cnpj):
limpando_cnpj = ''
for num in cnpj[:15]:
if num.isdigit():
limpando_cnpj += num
return limpando_cnpj