-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Location): script to fill in OSM brand & version (#592)
- Loading branch information
Showing
2 changed files
with
56 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
open_prices/locations/management/commands/set_location_osm_brand_and_version.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import time | ||
|
||
from django.core.management.base import BaseCommand | ||
|
||
from open_prices.common import openstreetmap as common_openstreetmap | ||
from open_prices.locations.models import Location | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Init Location osm_brand & osm_version fields (depending on it's creation date!)." | ||
|
||
def handle(self, *args, **options) -> None: # type: ignore | ||
qs = Location.objects.has_type_osm() | ||
self.stdout.write(f"Found {qs.count()} OSM locations...") | ||
qs = qs.filter(osm_version=None) | ||
self.stdout.write( | ||
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 |