0
I need to extract the information from a cnab file (which is a text file), be able to read the file using python.read
but I don’t know how to progress.
Contents of the file:
39900000 2957742120001329999999999 00009900000000000990GRUPO NEXXERA HSBC NEXXERA 107062017095759000000102001600
39900011C2001010 2957742120001329999999999 00009900000000000990GRUPO NEXXERA Rua Madalena Barbi 181 Centro-Florianopolis88015190SC
3990001300001A00000039900001900000000001090EMPRESA FORNECEDOR 1 0000000001 07062017BRL000000000000000000000000000010 00000000000000000000000 0
3990001300002A00070039900002900000000002090EMPRESA FORNECEDOR 2 0000000002 07062017BRL000000000000000000000000020020 00000000000000000000000 0
3990001300003A00001839900003900000000003090EMPRESA FORNECEDOR 3 0000000003 07062017BRL000000000000000000000003030030 00000000000000000000000 0
39900015 000005000000000003050060000000000000000000000000
39999999 000001000007000000
code:
def abre_aquivo():
conteudo = open("modelo_arquivo.txt", 'r', encoding="utf-8")
conteudo_formatado = conteudo.read()
# print(type(conteudo_formatado))
x = conteudo_formatado.split()
print(x)
conteudo.close()
abre_aquivo()
Expected report:
------------------------------------------------------------------------------------------------------------------------------------------------------------
Nome da Empresa | Numero de Inscricao da Empresa | Nome do Banco | Nome da Rua | Numero do Local | Nome da Cidade | CEP | Sigla do Estado
------------------------------------------------------------------------------------------------------------------------------------------------------------
EMPRESA XX | 00.000.000/0000-00 | XXX | Rua Madalena Barbi | 181 | Centro-Florianopolis | 00000-000 | SC
------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------
Nome do Favorecido | Data de Pagamento | Valor do Pagamento | Numero do Documento Atribuido pela Empresa | Forma de Lancamento
--------------------------------------------------------------------------------------------------------------------------------------
EMPRESA FORNECEDOR 1 | 07/06/2017 | R$ 0,10 | 0000000001 | Credito em Conta Corrente
EMPRESA FORNECEDOR 2 | 07/06/2017 | R$ 200,20 | 0000000002 | Credito em Conta Corrente
EMPRESA FORNECEDOR 3 | 07/06/2017 | R$ 30.300,30 | 0000000003 | Credito em Conta Corrente
--------------------------------------------------------------------------------------------------------------------------------------
Would have some chunk of code for analysis or logs/errors to be checked as well as the file 'cnab'?
– Bart
I put the contents of the file and the code I have in the question.
– lucazpinheiro
What information do you need to extract? What is the format of this file? Are columns or something like that?
– Woss
The FEBRABAN website has these patterns set, you came to read?
– fernandosavio
Yes, I read the documentation of the site, but it did not help the issue of extraction.
– lucazpinheiro
I didn’t understand how it didn’t help... It is in these files that specify the structure of the files
.cnab
. For example: the first 3 digits are the bank’s FEBRABAN code, which in your case is399
, which is HSBC. What’s stopping you from extracting the information? Not knowing the file structure or not knowing how to do it in Python?– fernandosavio
It is the file structure that remains confused, parse in python I know quiet. By the way I need to read more of the documentation.
– lucazpinheiro