Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from HomebyTwo/improvement/hb2-66
HB2-66 import places from geonames.org
- Loading branch information
Showing
59 changed files
with
2,962 additions
and
870 deletions.
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
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
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
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,29 @@ | ||
import json | ||
|
||
from django.contrib.gis.geos import GEOSGeometry | ||
|
||
import requests | ||
|
||
from homebytwo.routes.models.country import Country | ||
|
||
GEO_COUNTRIES_URL = ( | ||
"https://raw.githubusercontent.com/" | ||
"datasets/geo-countries/master/data/countries.geojson" | ||
) | ||
|
||
|
||
def import_country_geometries(): | ||
print("importing country geometries...") | ||
response = requests.get(GEO_COUNTRIES_URL) | ||
response.raise_for_status() | ||
geom_json = response.json() | ||
for country in geom_json["features"]: | ||
defaults = { | ||
"name": country["properties"]["ADMIN"], | ||
"iso2": country["properties"]["ISO_A2"], | ||
"geom": GEOSGeometry(json.dumps(country["geometry"])), | ||
} | ||
Country.objects.update_or_create( | ||
iso3=country["properties"]["ISO_A3"], | ||
defaults=defaults, | ||
) |
Oops, something went wrong.