Skip to content

Commit

Permalink
import_areas script with more diagnostic output
Browse files Browse the repository at this point in the history
  • Loading branch information
struan committed Sep 18, 2024
1 parent 280d1c0 commit cfe37b7
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions hub/management/commands/import_areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,13 @@ def add_arguments(self, parser):
)

def handle(self, quiet: bool = False, *args, **options):
quiet = True
mapit_client = mapit.MapIt()
for b_type in self.boundary_types:
areas = mapit_client.areas_of_type(b_type["mapit_type"])
print(
f"fetched mapit areas with type {b_type['mapit_type']}, our type {b_type['code']}"
)
area_type, created = AreaType.objects.get_or_create(
code=b_type["code"],
area_type=b_type["area_type"],
Expand All @@ -56,6 +60,7 @@ def handle(self, quiet: bool = False, *args, **options):
if not quiet:
print(f"Importing {b_type['name']} Areas")
for area in tqdm(areas, disable=quiet):
print(f"looking at {area['name']}, mapit type {area['type']}")
try:
geom = mapit_client.area_geometry(area["id"])
geom = {
Expand All @@ -72,6 +77,9 @@ def handle(self, quiet: bool = False, *args, **options):
print(f"could not find mapit area for {area['name']}")
geom = None

print(
f"creating area for {area['name']} with GSS {area['codes']['gss']}, mapit_id {area['id']}"
)
a, created = Area.objects.update_or_create(
name=area["name"],
area_type=area_type,
Expand All @@ -83,3 +91,6 @@ def handle(self, quiet: bool = False, *args, **options):

a.geometry = geom
a.save()
print("--")

print("\n\033[31m######################\033[0m\n")

0 comments on commit cfe37b7

Please sign in to comment.