From 5ec8ccde085bfbe8a32ca6c9a1bea916de24bd94 Mon Sep 17 00:00:00 2001 From: Alexander Griffen Date: Wed, 13 Mar 2024 15:41:47 +0000 Subject: [PATCH] FIX: Update generation script to handle GSS codes differently --- .../generate_wildlife_trust_nature_reserves_csv.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/hub/management/commands/generate_wildlife_trust_nature_reserves_csv.py b/hub/management/commands/generate_wildlife_trust_nature_reserves_csv.py index 4f7aa3e2d..98deb3616 100644 --- a/hub/management/commands/generate_wildlife_trust_nature_reserves_csv.py +++ b/hub/management/commands/generate_wildlife_trust_nature_reserves_csv.py @@ -8,6 +8,7 @@ import requests from tqdm import tqdm +from hub.models import Area from utils.mapit import ( BadRequestException, ForbiddenException, @@ -27,6 +28,10 @@ class Command(BaseCommand): out_file = settings.BASE_DIR / "data" / "wildlife_trust_reserves.csv" + con_gss_codes = list( + set([value["gss"] for value in list(Area.objects.values("gss"))]) + ) + def get_dataframe(self): if not self._quiet: self.stdout.write("Downloading data from API") @@ -72,7 +77,9 @@ def get_gss_code(self, mapit, postcode): sleep(60) return self.get_gss_code(mapit, postcode) if gss_code: - return gss_code[0] + for code in gss_code: + if code in self.con_gss_codes: + return code def process_data(self, df): if not self._quiet: