Skip to content

Commit

Permalink
fix(Location): add try/catch & progress in OSM script. ref #592
Browse files Browse the repository at this point in the history
  • Loading branch information
raphodn committed Dec 3, 2024
1 parent ea29002 commit 887b508
Showing 1 changed file with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,21 @@ def handle(self, *args, **options) -> None: # type: ignore
f"Of which {qs.count()} have their osm_version field empty..."
)

for location in qs.all():
response = common_openstreetmap.get_historical_location_from_openstreetmap(
location.osm_id, location.osm_type, location.created
)
if response:
location.osm_brand = response.tag("brand")
location.osm_version = response.version()
location.save(update_fields=["osm_brand", "osm_version"])
else:
self.stdout.write(f"Could not find historical data for {location}")
time.sleep(1) # be nice to the OSM API
for index, location in enumerate(qs.all()):
try:
response = (
common_openstreetmap.get_historical_location_from_openstreetmap(
location.osm_id, location.osm_type, location.created
)
)
if response:
location.osm_brand = response.tag("brand")
location.osm_version = response.version()
location.save(update_fields=["osm_brand", "osm_version"])
else:
self.stdout.write(f"Could not find historical data for {location}")
if index % 100 == 0:
print(index)
time.sleep(1) # be nice to the OSM API
except Exception as e:
self.stdout.write(f"Error with {location}: {e}")

0 comments on commit 887b508

Please sign in to comment.