Skip to content

Instantly share code, notes, and snippets.

@MaxMorais
Last active June 4, 2021 18:36
Show Gist options
  • Save MaxMorais/03ae549883eadb0dc849bcc2ab7e2c48 to your computer and use it in GitHub Desktop.
Save MaxMorais/03ae549883eadb0dc849bcc2ab7e2c48 to your computer and use it in GitHub Desktop.
from collections import namedtuple
Linha = namedtuple('Linha', ('DAtras'))
novo_conteudo = []
with open('./meu-arquivo.txt') as f:
conteudo = f.readlines()
inicio_encontrado = False
while not inicio_encontrado:
linha = conteudo.pop(0)
if 'Histórico de pagamento' not in linha:
continue
else:
inicio_encontrado = True
for linha in conteudo:
if '--' in linha:
continue
elif not linha:
continue
linha = list(filter(None, map(lambda valor: valor.strip(), linha.split('|'))))
if not linha:
continue
try:
novo_conteudo.append(
Linha(int(linha[1]) if '-' not in linha[1] else (int(linha[1].replace('-', '')) * -1))
)
except ValueError as e:
continue
for linha in novo_conteudo:
print(linha._asdict())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment