from tqdm import tqdm from epc_data.temp_inputs import input_data from epc_data.Property import Property from epc_data.config import EPC_AUTH_TOKEN from epc_api.client import EpcClient from epc_data.downloader import pagenated_epc_download from epc_data.EpcClean import EpcClean def handler(): # To begin with, the input data is a list of dictionaries, however we would read this file in epc_client = EpcClient(auth_token=EPC_AUTH_TOKEN) input_properties = [ Property(postcode=config['postcode'], address1=config['address1'], epc_client=epc_client) for config in input_data ] for p in input_properties: p.search_address_epc() local_authorities = {p.data['local-authority'] for p in input_properties} data = [] for la in tqdm(local_authorities): data.extend( pagenated_epc_download( client=epc_client, params={"local-authority": la}, page_size=5000, n_pages=10, ) ) cleaner = EpcClean(data) cleaner.clean()