Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download all country maps & Use OSM instead of google maps for locations #220

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
41 changes: 41 additions & 0 deletions wbcore/management/commands/download_country_maps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from django.core.management.base import BaseCommand, no_translations
import urllib.request
from django.conf import settings
from os import path, makedirs
from pathlib import Path
import json



class Command(BaseCommand):
"""
Creates slugs based on the name for each partner without slug.
"""
@no_translations
def handle(self, *args, **options):
env_path = Path(settings.ENV_PATH)
local_static_path = env_path.parent / 'wbcore' / 'static'
static_location = local_static_path if settings.DEBUG else settings.SERVER_STATIC_ROOT
bhemmer marked this conversation as resolved.
Show resolved Hide resolved

path_highmaps_countries = static_location / 'highmaps' / 'countries'
bhemmer marked this conversation as resolved.
Show resolved Hide resolved
print('Save files in ' + str(path_highmaps_countries))
if not path.exists(path_highmaps_countries):
makedirs(path_highmaps_countries)

with open(str(path_highmaps_countries.parent) + '/world-robinson-highres.geo.json') as f:
world_data = json.load(f)

print('Beginning file downloads with urllib2...')
# Iterating through the json list
count = 0
for country in world_data['features']:
country_code = country['properties']['hc-key']
print('download country: ' + country['properties']['name'])
url = 'https://code.highcharts.com/mapdata/countries/{}/{}-all.js'.format(country_code, country_code)
try:
urllib.request.urlretrieve(url, str(path_highmaps_countries / country_code) + '.js')
count += 1
except:
ToppAce marked this conversation as resolved.
Show resolved Hide resolved
print('country {} with code {} cannot be downloaded'.format(country['properties']['name'], country_code))

print("created {} country files".format(count))
2 changes: 2 additions & 0 deletions wbcore/static/highmaps/countries/ad.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading