Skip to content

Commit

Permalink
improve debug to search for error
Browse files Browse the repository at this point in the history
  • Loading branch information
jrafaelrn committed Apr 23, 2024
1 parent 3f4803b commit 9729de7
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions src/functions/bd_update_banks/bank_sicredi.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import os, extract, bd, time, json, re
from datetime import datetime
import pandas as pd
import logging


logger = logging.getLogger(__name__)

acumulado = []
contador_acumulado = 0



##########################################
# SICREDI #
##########################################
Expand All @@ -16,7 +18,8 @@
def import_extrato_sicredi(extrato_file, account_name):

global acumulado
print(f'... Importing extrato {account_name} from File {extrato_file} ...')
global contador_acumulado
logger.info(f'... Importing extrato {account_name} from File {extrato_file} ...')

in_progress = False
import_card = False
Expand All @@ -38,11 +41,11 @@ def import_extrato_sicredi(extrato_file, account_name):
saldo = line[1][4]


print(f'\nImporting date {line[1][0]}')
print(f'\tConta: {conta}')
print(f'\tDescricao: {descricao}')
print(f'\tTipo: {tipo}')
print(f'\tValor: {valor}')
logger.debug(f'\nImporting date {line[1][0]}')
logger.debug(f'\tConta: {conta}')
logger.debug(f'\tDescricao: {descricao}')
logger.debug(f'\tTipo: {tipo}')
logger.debug(f'\tValor: {valor}')


# Se encontrar uma fatura de cartao, procura o arquivo separado
Expand Down Expand Up @@ -73,8 +76,8 @@ def import_extrato_sicredi(extrato_file, account_name):
except Exception as e:

data = None
print(f'Linha inválida: [0]:{line[1][0]} [1]:{line[1][1]} [2]:{line[1][2]} [3]:{line[1][3]} [4]:{line[1][4]}')
print(f'Erro: {e}')
logger.warning(f'Linha inválida: [0]:{line[1][0]} [1]:{line[1][1]} [2]:{line[1][2]} [3]:{line[1][3]} [4]:{line[1][4]}')
logger.warning(f'Erro: {e}')


if in_progress:
Expand All @@ -100,16 +103,17 @@ def import_accumulated_sicredi(data_transaction):

global acumulado
global contador_acumulado
max_acumulado = 5
MAX_ACUMULADO = 5


if contador_acumulado <= max_acumulado:
if contador_acumulado < MAX_ACUMULADO:

contador_acumulado += 1
acumulado.append(data_transaction)

else:

logger.debug(f'Enviando {contador_acumulado} lançamentos para o BD - Dados acumulados: {acumulado}')
bd.insert(acumulado)
acumulado = []
contador_acumulado = 0
Expand Down

0 comments on commit 9729de7

Please sign in to comment.