refactoring

This commit is contained in:
Khalim Conn-Kowlessar 2025-02-21 15:25:38 +00:00
parent d86ab5ff8d
commit 759e81f660
2 changed files with 17 additions and 6 deletions

View file

@ -21,13 +21,21 @@ EPC_AUTH_TOKEN = os.getenv("EPC_AUTH_TOKEN")
def get_data(
asset_list, fulladdress_column, address1_column, postcode_column, manual_uprn_map,
df, fulladdress_column, address1_column, postcode_column, manual_uprn_map,
uprn_column=None, epc_api_only=False, row_id_name="row_id"
):
# These re-map the standard property types to forms accepted by the EPC api, so we can predict EPCs
property_type_map = {
"house": "House",
"flat": "Flat",
"maisonette": "Maisonette",
"bungalow": "Bungalow",
}
epc_data = []
errors = []
no_epc = []
for _, home in tqdm(asset_list.iterrows(), total=len(asset_list)):
for _, home in tqdm(df.iterrows(), total=len(df)):
try:
postcode = home[postcode_column]
house_number = str(home[address1_column]).strip()
@ -42,19 +50,21 @@ def get_data(
if pd.isnull(uprn):
uprn = None
property_type = property_type_map.get(home[AssetList.STANDARD_PROPERTY_TYPE], None)
searcher = SearchEpc(
address1=str(house_no),
postcode=postcode,
auth_token=EPC_AUTH_TOKEN,
os_api_key="",
property_type=None,
property_type=property_type,
fast=True,
full_address=full_address,
max_retries=5,
uprn=uprn
)
# Force the skipping of estimating the EPC
searcher.ordnance_survey_client.property_type = None
searcher.ordnance_survey_client.property_type = property_type
searcher.ordnance_survey_client.built_form = None
searcher.find_property(skip_os=True)
@ -317,7 +327,7 @@ def app():
continue
chunk = asset_list.standardised_asset_list[i:i + chunk_size]
epc_data_chunk, errors_chunk, no_epc_chunk = get_data(
asset_list=chunk,
df=chunk,
row_id_name=asset_list.DOMNA_PROPERTY_ID,
fulladdress_column=asset_list.STANDARD_FULL_ADDRESS,
address1_column=asset_list.STANDARD_ADDRESS_1,

View file

@ -8,4 +8,5 @@ boto3
openpyxl
openai
tiktoken
msgpack
msgpack
beautifulsoup4