From 1250f65ab1022bd4e001b3d3a52745e1aa142a08 Mon Sep 17 00:00:00 2001 From: Joel Balcaen Date: Fri, 26 Apr 2024 11:13:58 -0300 Subject: [PATCH] fix --- .vscode/launch.json | 5 ++++- lambdas/document_filler/src/index.py | 6 +++--- lambdas/document_filler/src/requirements.txt | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 879b520..c35505c 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -17,7 +17,10 @@ "lambda": { "runtime": "python3.11", "payload": { - "json": {} + "json": { + "doc_s3_arn": "arn:aws:s3:::levio-demo-fev-esta-ses-bucket-dev/rfp/pv7jfmrt7rb5713phc1nbujbiprs8kep6jq6cm01/attachments/MESS_700001817_Gouv_Arch_Securite_extracted_pdf_content.txt", + "replacements": [] + } } } }, diff --git a/lambdas/document_filler/src/index.py b/lambdas/document_filler/src/index.py index 7393037..9cbb72e 100644 --- a/lambdas/document_filler/src/index.py +++ b/lambdas/document_filler/src/index.py @@ -6,7 +6,7 @@ def lambda_handler(event, context): """ - Downloads the given docx and for each replacement item it replaces the matching document_key with the text_to_fill + Downloads the given docx and for each replacement item it replaces the matching replacement_key with the replacement_text """ s3_arn = event['doc_s3_arn'] replacements = event['replacements'] @@ -23,8 +23,8 @@ def lambda_handler(event, context): for paragraph in doc.paragraphs: for replacement in replacements: - if replacement['document_key'] in paragraph.text: - paragraph.text = paragraph.text.replace(replacement['document_key'], replacement['text_to_fill']) + if replacement['replacement_key'] in paragraph.text: + paragraph.text = paragraph.text.replace(replacement['replacement_key'], replacement['replacement_text']) output_stream = BytesIO() doc.save(output_stream) diff --git a/lambdas/document_filler/src/requirements.txt b/lambdas/document_filler/src/requirements.txt index 7a6646f..09749b6 100644 --- a/lambdas/document_filler/src/requirements.txt +++ b/lambdas/document_filler/src/requirements.txt @@ -1 +1 @@ -docx \ No newline at end of file +python-docx \ No newline at end of file