Skip to content

Instantly share code, notes, and snippets.

@myf
Created April 2, 2014 19:55
Show Gist options
  • Save myf/9941876 to your computer and use it in GitHub Desktop.
Save myf/9941876 to your computer and use it in GitHub Desktop.
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