From 9eed49c3449e060dcd201de36153a0d5fb5730c3 Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Thu, 3 Oct 2024 20:10:06 +0200 Subject: [PATCH] Consider last transaction --- bnp_pdf_statement_parser.py | 14 +++++++++----- utils.py | 13 ++++++++++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/bnp_pdf_statement_parser.py b/bnp_pdf_statement_parser.py index 84fd36d..02e1763 100755 --- a/bnp_pdf_statement_parser.py +++ b/bnp_pdf_statement_parser.py @@ -10,7 +10,7 @@ PATH = f'/home/benjamin/Desktop/bens_folder/bazaar/documents/bnp/bank_statements os.chdir(PATH) -PRINT_TRANSACTIONS = False +PRINT_TRANSACTIONS = True MAIN_BANK_ACCOUNT = 'compte_de_cheques' @@ -22,10 +22,13 @@ for folder in os.listdir(): print(folder) for file in os.listdir(folder): print(file) - fileDatetime = getDatetimeFromFileName(file) - print(fileDatetime) - #otherBankAccountsCredits[fileDatetime] = otherBankAccountsCredits.get(fileDatetime, 0) + + filePath = f'{folder}/{file}' + initialAmount, totalMonthlyDebit, totalMonthlyCredit, transactions, fileDatetime = readPdfBankStatement(filePath) + print(totalMonthlyCredit) + print(transactions) + otherBankAccountsCredits[fileDatetime] = otherBankAccountsCredits.get(fileDatetime, 0) + totalMonthlyCredit +#exit(1) os.chdir(f'{MAIN_BANK_ACCOUNT}/') totalMonthlyDebits = [] @@ -45,13 +48,14 @@ for folder in sorted(os.listdir()): print(f'Total monthly debit: {totalMonthlyDebit}') print(f'Total monthly credit: {totalMonthlyCredit}') totalMonthlyDebits += [totalMonthlyDebit] + totalMonthlyCredit += otherBankAccountsCredits.get(fileDatetime, 0) totalMonthlyCredits += [totalMonthlyCredit] totalMonthlyDifference = totalMonthlyCredit - totalMonthlyDebit totalMonthlyDifferences += [totalMonthlyDifference] if PRINT_TRANSACTIONS: for transaction in transactions: print(transaction['date'], transaction['valeur'], transaction['amount'], transaction['currentAmount']) - print('\n'.join(transaction['comment'])) + print(transaction['comment']) print() if firstDatetime is None: firstDatetime = fileDatetime diff --git a/utils.py b/utils.py index 686ca90..d8f909c 100644 --- a/utils.py +++ b/utils.py @@ -63,11 +63,9 @@ def readPdfBankStatement(filePath): else: totalMonthlyCredit = toFloat(TOTAL_DES_OPERATIONS_CREDIT_ONLY_REGEX.match(line).group(1)) totalMonthlyDebit = 0 - #if os.getcwd().endswith(f'/{MAIN_BANK_ACCOUNT}'): - # totalMonthlyCredit += otherBankAccountsCredits[fileDatetime] - break if FIRST_LINE_OF_PAYMENT_REGEX.match(line) is not None: + #print(line) if date is not None: transactions += [{ 'date': date, @@ -76,10 +74,19 @@ def readPdfBankStatement(filePath): 'currentAmount': currentAmount, 'comment': '\n'.join(comment) }] + date = None date, valeur, amount = line.split() amount = float(amount.replace(',', '.')) currentAmount -= amount comment = [] else: comment += [line] + if date is not None: + transactions += [{ + 'date': date, + 'valeur': valeur, + 'amount': amount, + 'currentAmount': currentAmount, + 'comment': '\n'.join(comment) + }] return initialAmount, totalMonthlyDebit, totalMonthlyCredit, transactions, fileDatetime \ No newline at end of file