From 9e8de4b4c76f64d78c53db3c27105c12bf0c1ded Mon Sep 17 00:00:00 2001 From: Benjamin Loison Date: Thu, 3 Oct 2024 21:33:38 +0200 Subject: [PATCH] WIP gather all transactions over bank accounts --- bnp_pdf_statement_parser.py | 38 +++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/bnp_pdf_statement_parser.py b/bnp_pdf_statement_parser.py index 9a12116..ff30069 100755 --- a/bnp_pdf_statement_parser.py +++ b/bnp_pdf_statement_parser.py @@ -19,18 +19,29 @@ credits_ = [] # Precise bank account allTransactions = [] -def appendTransactions() +''' +def appendTransactions(x): + global allTransactions + allTransactions += [x] +''' + +def appendTransactions(transactions, bankAccount): + global allTransactions + #print('Before') + #pprint(allTransactions) + for transaction in transactions: + transaction['bank account'] = bankAccount + allTransactions += [transaction] + #print('After') + #pprint(allTransactions) for folder in os.listdir(): if folder != MAIN_BANK_ACCOUNT: - print(folder) for file in os.listdir(folder): - print(file) filePath = f'{folder}/{file}' - _initialAmount, _totalMonthlyDebit, _totalMonthlyCredit, transactions, fileDatetime = readPdfBankStatement(filePath) - for transaction in transactions: - transaction['bank account'] = folder - allTransactions += [transaction] + print(filePath) + transactions = readPdfBankStatement(filePath)[3] + appendTransactions(transactions, folder) #exit(1) os.chdir(f'{MAIN_BANK_ACCOUNT}/') @@ -39,16 +50,19 @@ for folder in sorted(os.listdir()): for file in sorted(os.listdir(folder)): filePath = f'{folder}/{file}' print(filePath) - initialAmount, totalMonthlyDebit, totalMonthlyCredit, transactions, fileDatetime = readPdfBankStatement(filePath) - for transaction in transactions: - transaction['bank account'] = MAIN_BANK_ACCOUNT - allTransactions += [transaction] + transactions = readPdfBankStatement(filePath)[3] + appendTransactions(transactions, MAIN_BANK_ACCOUNT) if PRINT_TRANSACTIONS: for transaction in transactions: printTransaction(transaction) #break #break -lastDatetime = getDatetimeFromFileName(file) + +from pprint import pprint +#pprint(transactions) +pprint(allTransactions) + +exit(0) fig, ax = plt.subplots() plt.title('Monthly debits and credits')