From 86ca5b40074015c20dd35fe38eda7ac3799139f4 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Mon, 28 Oct 2024 19:50:09 +0000 Subject: [PATCH] addded catch for condition report --- .idea/Model.iml | 2 +- .idea/misc.xml | 2 +- .../livewest/route_march_2024_10_28.py | 69 ++++++++++--------- .../stonewater/Wave 3 Preparation.py | 2 +- 4 files changed, 40 insertions(+), 35 deletions(-) diff --git a/.idea/Model.iml b/.idea/Model.iml index 850c0cda..762580d9 100644 --- a/.idea/Model.iml +++ b/.idea/Model.iml @@ -7,7 +7,7 @@ - + diff --git a/.idea/misc.xml b/.idea/misc.xml index e4070118..c916a158 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -3,7 +3,7 @@ - + diff --git a/etl/customers/livewest/route_march_2024_10_28.py b/etl/customers/livewest/route_march_2024_10_28.py index fff1e7e7..47b86e89 100644 --- a/etl/customers/livewest/route_march_2024_10_28.py +++ b/etl/customers/livewest/route_march_2024_10_28.py @@ -1,4 +1,5 @@ import os +import time import pandas as pd from tqdm import tqdm @@ -46,42 +47,46 @@ def app(): ) epc_data = [] + errors = [] for _, home in tqdm(asset_list.iterrows(), total=len(asset_list)): - - postcode = home["Postcode"] - house_number = home["Number"] - full_address = home["Full Address"] - - searcher = SearchEpc( - address1=str(house_number), - postcode=postcode, - auth_token=EPC_AUTH_TOKEN, - os_api_key="", - property_type=None, - fast=True, - full_address=full_address - ) - # Force the skipping of estimating the EPC - searcher.ordnance_survey_client.property_type = None - searcher.ordnance_survey_client.built_form = None - - searcher.find_property(skip_os=True) - if searcher.newest_epc is None: - continue - - # Look for EPC recommendatons try: - property_recommendations = searcher.client.domestic.recommendations(searcher.newest_epc["lmk-key"]) - except: - property_recommendations = {"rows": []} + postcode = home["Postcode"] + house_number = home["Number"] + full_address = home["Full Address"] - epc = { - "asset_list_address": full_address, - **searcher.newest_epc.copy(), - "recommendations": property_recommendations["rows"] - } + searcher = SearchEpc( + address1=str(house_number), + postcode=postcode, + auth_token=EPC_AUTH_TOKEN, + os_api_key="", + property_type=None, + fast=True, + full_address=full_address + ) + # Force the skipping of estimating the EPC + searcher.ordnance_survey_client.property_type = None + searcher.ordnance_survey_client.built_form = None - epc_data.append(epc) + searcher.find_property(skip_os=True) + if searcher.newest_epc is None: + continue + + # Look for EPC recommendatons + try: + property_recommendations = searcher.client.domestic.recommendations(searcher.newest_epc["lmk-key"]) + except: + property_recommendations = {"rows": []} + + epc = { + "asset_list_address": full_address, + **searcher.newest_epc.copy(), + "recommendations": property_recommendations["rows"] + } + + epc_data.append(epc) + except Exception as e: + errors.append(e) + time.sleep(5) epc_df = pd.DataFrame(epc_data) diff --git a/etl/customers/stonewater/Wave 3 Preparation.py b/etl/customers/stonewater/Wave 3 Preparation.py index 8e1a7fdb..fc11f1c0 100644 --- a/etl/customers/stonewater/Wave 3 Preparation.py +++ b/etl/customers/stonewater/Wave 3 Preparation.py @@ -178,7 +178,7 @@ def is_condition_report(text): """ Determines if the provided text indicates that the PDF is a Condition Report. """ - return text.startswith("OsmosisACDNEWPAS2035ConditionReport") + return text.startswith("OsmosisACDNEWPAS2035ConditionReport") or text.startswith("OsmosisACDPAS2035ConditionReport") def main():