diff --git a/hub/management/commands/import_areas.py b/hub/management/commands/import_areas.py index ceec5d25..78aae6dd 100644 --- a/hub/management/commands/import_areas.py +++ b/hub/management/commands/import_areas.py @@ -40,14 +40,20 @@ def add_arguments(self, parser): "-q", "--quiet", action="store_true", help="Silence progress bars." ) - def handle(self, quiet: bool = False, *args, **options): - quiet = True + parser.add_argument( + "--diagnostics", + action="store_true", + help="Print out extra diagnostics - very verbose", + ) + + def handle(self, quiet: bool = False, diagnostics: bool = False, *args, **options): 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']}" - ) + if diagnostics: + 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"], @@ -57,10 +63,12 @@ def handle(self, quiet: bool = False, *args, **options): }, ) - if not quiet: + if diagnostics or 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']}") + disable = quiet or diagnostics + for area in tqdm(areas, disable=disable): + if diagnostics: + print(f"looking at {area['name']}, mapit type {area['type']}") try: geom = mapit_client.area_geometry(area["id"]) geom = { @@ -77,9 +85,10 @@ 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']}" - ) + if diagnostics: + print( + f"creating area for {area['name']} with GSS {area['codes']['gss']}, mapit_id {area['id']}" + ) try: a, created = Area.objects.update_or_create( name=area["name"], @@ -97,6 +106,8 @@ def handle(self, quiet: bool = False, *args, **options): a.geometry = geom a.save() - print("--") + if diagnostics: + print("--") - print("\n\033[31m######################\033[0m\n") + if diagnostics: + print("\n\033[31m######################\033[0m\n")