-
-
Save shakythesherpa/10027381 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
try: | |
import simplejson as json | |
except: | |
import json | |
import re | |
import requests | |
dir_url = 'http://api.tiles.mapbox.com/v3/modilabs/maps.json' | |
map_data = json.load(requests.get(dir_url).text) | |
nmis_exp = re.compile("Nigeria|nigeria|nmis") | |
nmis_tiles = [m['download'] for m in j if re.match(nmis_exp, m['name'])] | |
def get_name(url): | |
name_exp = re.compile("http\:\/\/a\.tiles\.mapbox\.com\/v3\/modilabs\.") | |
url = re.sub(init_exp, '', url) | |
return url | |
def get_file(url): | |
res = requests.get(url) | |
name = get_name(url) | |
with open("mbtiles/%s" % name, 'wb') as w: | |
w.write(res.content) | |
for item in nmis_tiles: | |
print("start downloading %s" % item) | |
get_file(item) | |
print("finished downloading %s" % item) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment