Replace "\n" with n in Python scripts

This commit is contained in:
Benjamin Loison 2023-07-28 14:54:53 +02:00
parent c775a3056d
commit 9ceaa935b7
Signed by: Benjamin_Loison
SSH Key Fingerprint: SHA256:BtnEgYTlHdOg1u+RmYcDE0mnfz1rhv5dSbQ2gyxW8B8

View File

@ -2,7 +2,7 @@
# Depends on `pdftotext`. # Depends on `pdftotext`.
import os, subprocess, shlex, re, config import os, subprocess, re, config
path = f'/home/benjamin/Desktop/bens_folder/bazaar/documents/bnp/RLV_CHQ_{config.RLV_CHQ}' path = f'/home/benjamin/Desktop/bens_folder/bazaar/documents/bnp/RLV_CHQ_{config.RLV_CHQ}'
@ -20,11 +20,10 @@ Assuming file hierarchy like:
''' '''
def execute(command): def execute(command):
return subprocess.check_output(command, shell = True).decode('utf-8') return subprocess.check_output(command, shell).decode('utf-8')
def getTextFromPdf(pdfPath): def getTextFromPdf(pdfPath):
pdfPath = shlex.quote(pdfPath) return execute(['pdftotext', '-raw', pdfPath, '-')
return execute(f'pdftotext -raw {pdfPath} -')
firstLineOfPaymentRegex = re.compile('\d{2}\.\d{2} \d{2}\.\d{2} \d+,\d{2}') firstLineOfPaymentRegex = re.compile('\d{2}\.\d{2} \d{2}\.\d{2} \d+,\d{2}')
endPageAfterTheFirstOneRegex = re.compile('P\. \d+/\d+') endPageAfterTheFirstOneRegex = re.compile('P\. \d+/\d+')
@ -67,7 +66,7 @@ for folder in os.listdir():
if firstLineOfPaymentRegex.match(line) != None: if firstLineOfPaymentRegex.match(line) != None:
if date != None: if date != None:
print(date, valeur, amount, currentAmount) print(date, valeur, amount, currentAmount)
print("\n".join(comment)) print('\n'.join(comment))
print() print()
date, valeur, amount = line.split() date, valeur, amount = line.split()
amount = float(amount.replace(',', '.')) amount = float(amount.replace(',', '.'))