From d1675e84786b0515bf069462e1886bbaf616e487 Mon Sep 17 00:00:00 2001 From: Khalim Conn-Kowlessar Date: Fri, 16 Jun 2023 15:29:06 +0100 Subject: [PATCH] added get_coordinates --- model_data/Property.py | 14 +++++++++++--- model_data/app.py | 3 +++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/model_data/Property.py b/model_data/Property.py index a5058191..22413c7a 100644 --- a/model_data/Property.py +++ b/model_data/Property.py @@ -4,6 +4,7 @@ from model_data.OpenUprnClient import OpenUprnClient class Property: + coordinates = None def __init__(self, postcode, address1, epc_client=None, data=None): self.postcode = postcode @@ -37,11 +38,18 @@ class Property: self.data = response["rows"][0] - def get_coordinates(self, open_oprn_client: OpenUprnClient): + def get_coordinates(self, open_uprn_client: OpenUprnClient): """ This method utlises the OpenOprnClient to get the coordinates of the property The OpenOprnClient interfactes with the Ordinance Survey Open UPRN database to extract property coordinates. This database holds lookups between UPRN and coordinates. - :param open_oprn_client: - :return: + :param open_uprn_client: Instance of OpenOprnClient. This method expects the client to have already read + the data """ + + if not open_uprn_client.data: + raise ValueError("OpenUprnClient has not read data") + + self.coordinates = open_uprn_client.data[ + open_uprn_client.data["UPRN"] == self.data["uprn"] + ].to_dict("records")[0] diff --git a/model_data/app.py b/model_data/app.py index a3a45e9e..d419639a 100644 --- a/model_data/app.py +++ b/model_data/app.py @@ -34,6 +34,9 @@ def handler(): ) open_urpn_client.read() + for p in input_properties: + p.get_coordinates(open_urpn_client) + local_authorities = {p.data['local-authority'] for p in input_properties} data = []