1
Editing: A previous function generates a list like this:
['Responsável atual', 'Número do processo', 'Foro de tramitação', 'Data da intimação 05/10/2017', 'Data da ação 15/08/2011']
This is the previous list in "Data". Data is my final report. It contains hundreds of processes listed. I take one by one of these processes, access and ADD the information from "Parties". That is, I INCREMENT this list with complementary information, which are, for example:
['Exequente', 'União', '(CNPJ do exequente)', 'Executado', '(CNPJ fictício) 00.345.123/0001-00', 'Nome da empresa executada']
My role TRAVERSES that list, FINDS the CNPJ (or CPF) target and TREATS that information to determine who will be NEW responsible. So there are several Eps, as he considers the number 3 (just before the bar). If there is 0, 9 or 8 it IGNORES and picks up the previous one (in this case, 2). If there is 0, 9 or 8 ignores and picks up the previous and so on, so it is a bit confusing the criterion of determination of the responsible. In the end, when I have determined who is responsible according to this criterion, I need to add all this new information from that list to that previous list (i.e., I add "Parties" + 'distributefor' to "Data") to complete the report...
#############################
I have a function:
def PegaDadosPartes(dados):
distribuicaoPara = VerificaDist(partes)
dados.append(str(distribuicaoPara) + " @")
for x in range(len(partes)):
dados.append(partes[x] + '@')
del partes[0:len(partes)]
return dados
It takes a data set (list 'parts') from another function, and feeds another list ('data') with this information, BEING THAT the variable 'distributionPara' calls the function 'Verificadist(parts)' to get its value.
This value depends on a number of treatments. Among them, check if in 'parts' there is CNPJ’s or CPF’s, and treat differently case by case, thus:
def VerificaDist(partes):
posicao = []
temCnpj = 0
for x in range(len(partes)):
verificaOutroCnpj = re.search("\d{2}.\d{3}.\d{3}/\d{4}-\d{2}", partes[x])
if verificaOutroCnpj:
posicao.append("CNPJ " + verificaOutroCnpj.group())
temCnpj = temCnpj + 1
verificaCpf = re.search("\d{3}.\d{3}.\d{3}-\d{2}", partes[x]) #Se não achou CNPJ, busca CPF.
if verificaCpf:
posicao.append("CPF " + verificaCpf.group())
if temCnpj > 0:
Caso1(posicao) #Primeiro caso: consta CNPJ.
else:
Caso2(posicao) #Segundo caso: consta CPF.
In either case, the treatment functions will "slice" the variable, as the treatment criteria are different. In the CNPJ the digit before the "/" determines the responsible one. In the CPF, the eighth digit defines this. The final function does this:
def TrataDistribuicao(alvos): #("Alvos" são as partes "fatiadas" da informação)
analisa = open('C:\\Regras.txt', 'r') #É o arquivo que contém as regras de designação de responsável, tipo "Se o dígito é 8 responsável fulano, se 7 cicrano" e assim por diante...
regrasDeDistribuicao = analisa.readlines()
for x in range(len(regrasDeDistribuicao)):
regrasDeDistribuicao[x] = regrasDeDistribuicao[x].split(',')
for x in range(len(regrasDeDistribuicao)):
if alvos[0] == regrasDeDistribuicao[x][0]:
distribuicaoPara = str("Distribuir para " + regrasDeDistribuicao[x][1] )
elif alvos[1] == regrasDeDistribuicao[x][0]:
distribuicaoPara = str("Distribuir para " + regrasDeDistribuicao[x][1])
elif alvos[2] == regrasDeDistribuicao[x][0]:
distribuicaoPara = str("Distribuir para " + regrasDeDistribuicao[x][1] )
elif alvos[3] == regrasDeDistribuicao[x][0]:
distribuicaoPara = str("Distribuir para " + regrasDeDistribuicao[x][1])
analisa.close()
It turns out, at the end of all this, I’m not getting "set" the variable "distributionPara". How to do?
Honestly, I reread your question about 5x and still can’t understand. You have a function,
PegaDadosPartes
, that receives only one parameter,dados
, and this function depends on the return of another function,VerificaDist
, you receive as a parameterpartes
, that does not even belong to the scope; the return of this function is added todados
, but then you iterate onpartes
, which, again, does not belong to the scope, adding its elements indados
, to finally returndados
. It didn’t make sense. I could explain exactly what you are trying to do, because I think that your solution is not feasible.– Woss
And why in function
TrataDistribuicao
there are 4if/elif
who do exactly the same thing?– Woss
I edited the question trying to be clearer. Thank you for your attention!!!
– Bergo de Almeida