Fix #2: Use amount sign to precise if it's a debit or a credit
				
					
				
			This commit is contained in:
		
							
								
								
									
										27
									
								
								utils.py
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								utils.py
									
									
									
									
									
								
							| @@ -50,16 +50,29 @@ def readPdfBankStatement(filePath): | ||||
|     date = None | ||||
|     comment = [] | ||||
|     transactions = [] | ||||
|     debitIndex = None | ||||
|     creditIndex = None | ||||
|     for line in lines: | ||||
|         if not started: | ||||
|             # We are interested in the content after this line:) | ||||
|             soldeCrediteurAuRegexMatch = SOLDE_CREDITEUR_AU_REGEX.match(line) | ||||
|             if soldeCrediteurAuRegexMatch is not None or (COLUMNS_HEADER.match(line) and not firstPage): | ||||
|             if COLUMNS_HEADER.match(line) is not None: | ||||
|                 getIndex = lambda line, type_: line.index(type_) + len(type_) | ||||
|                 debitIndex = getIndex(line, 'Débit') | ||||
|                 creditIndex = getIndex(line, 'Crédit') | ||||
|                 #print(f'{line.index("Débit") + len("Débit")=}') | ||||
|                 #print(f'{line.index("Crédit") + len("Crédit")=}') | ||||
|             if soldeCrediteurAuRegexMatch is not None or (COLUMNS_HEADER.match(line) is not None and not firstPage): | ||||
|                 if soldeCrediteurAuRegexMatch is not None: | ||||
|                     initialDate = datetime.strptime(soldeCrediteurAuRegexMatch.group(1), '%d.%m.%Y') | ||||
|                     initialAmount = toFloat(soldeCrediteurAuRegexMatch.group(2)) | ||||
|                     print(f'{initialAmount=}') | ||||
|                     #currentAmount = initialAmount | ||||
|                 ''' | ||||
|                 else: | ||||
|                     print(f'{line.index("Débit")=}') | ||||
|                     print(f'{line.index("Crédit")=}') | ||||
|                 ''' | ||||
|                 started = True | ||||
|                 continue | ||||
|         else: | ||||
| @@ -95,9 +108,15 @@ def readPdfBankStatement(filePath): | ||||
|                         #'currentAmount': currentAmount, | ||||
|                         'comment': '\n'.join(comment) | ||||
|                     }] | ||||
|                     #print('index', lastIndex(line, ' ')) | ||||
|                     #print(f'!{line}!') | ||||
|                     #print(amount, len(line)) | ||||
|                     date = None | ||||
|                 date, firstCommentLine, valeur, amount = firstLineOfPaymentRegexMatch.groups() | ||||
|                 lineLen = len(line) | ||||
|                 amount = toFloat(amount) | ||||
|                 if abs(debitIndex - lineLen) < abs(creditIndex - lineLen): | ||||
|                     amount *= -1 | ||||
|                 #currentAmount -= amount | ||||
|                 comment = [firstCommentLine] | ||||
|             elif line != '': | ||||
| @@ -111,4 +130,8 @@ def readPdfBankStatement(filePath): | ||||
|             #'currentAmount': currentAmount, | ||||
|             'comment': '\n'.join(comment) | ||||
|         }] | ||||
|     return initialAmount, totalMonthlyDebit, totalMonthlyCredit, transactions, fileDatetime | ||||
|     return initialAmount, totalMonthlyDebit, totalMonthlyCredit, transactions, fileDatetime | ||||
|  | ||||
| def lastIndex(myStr, character): | ||||
|     index = myStr[::-1].index(character) | ||||
|     return len(myStr) - index - 1 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user