From 9e752fca8db65d829cdac4ff15fc874fd086ad6d Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Tue, 29 Oct 2024 15:03:23 +0000 Subject: [PATCH] handling edge case extracting from summary report --- etl/customers/stonewater/Wave 3 Preparation.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/etl/customers/stonewater/Wave 3 Preparation.py b/etl/customers/stonewater/Wave 3 Preparation.py index 02a5cd83..0af43310 100644 --- a/etl/customers/stonewater/Wave 3 Preparation.py +++ b/etl/customers/stonewater/Wave 3 Preparation.py @@ -109,10 +109,12 @@ def extract_summary_report(pdf_path): data["Existing Primary Heating System"] = re.search(r"Main Heating Code\s*(.*?)\n", primary_text).group( 1).strip() - data["Existing Primary Heating PCDF Reference"] = re.search(r"PCDF boiler Reference\s*(\d+)", - primary_text).group(1) - data["Existing Primary Heating Controls"] = re.search(r"Main Heating Controls\s*(.*?)\n", primary_text).group( - 1).strip() + data["Existing Primary Heating PCDF Reference"] = re.search( + r"PCDF boiler Reference\s*(\d+)", primary_text + ).group(1) + data["Existing Primary Heating Controls"] = re.search( + r"Main Heating Controls\s*(.*?)\n", primary_text + ).group(1).strip() data["Existing Primary Heating % of Heat"] = int( re.search(r"Percentage of Heat\s*(\d+)\s*%", primary_text).group(1) ) @@ -125,8 +127,10 @@ def extract_summary_report(pdf_path): 1).strip() data["Existing Secondary Heating PCDF Reference"] = re.search(r"PCDF boiler Reference\s*(\d+)", secondary_text).group(1) - data["Existing Secondary Heating Controls"] = re.search(r"Main Heating Controls\s*(.*?)\n", - secondary_text).group(1).strip() + second_heating_controls_match = re.search(r"Main Heating Controls\s*(.*?)\n", secondary_text) + data["Existing Secondary Heating Controls"] = ( + second_heating_controls_match.group(1).strip() if second_heating_controls_match else "" + ) data["Existing Secondary Heating % of Heat"] = int( re.search(r"Percentage of Heat\s*(\d+)\s*%", secondary_text).group(1) ) @@ -287,7 +291,7 @@ def extract_epr(pdf_path): data["Existing Secondary Heating PCDF Reference"] = "" data["Existing Secondary Heating Controls"] = "" data["Existing Secondary Heating % of Heat"] = 0 - + else: secondary_text = secondary_heating_section.group(1)