From c8a4e47312e3d3e78f209e9d92ca3e4cc5fea90b Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Fri, 31 Jul 2015 10:16:38 +0200 Subject: [PATCH] script country downloader --- countries.json | 1 + downloader.py | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 countries.json create mode 100644 downloader.py diff --git a/countries.json b/countries.json new file mode 100644 index 0000000..22b2cbf --- /dev/null +++ b/countries.json @@ -0,0 +1 @@ +{"europe": ["albania", "andorra", "austria", "azores", "belarus", "belgium", "bosnia-herzegovina", "bulgaria", "croatia", "cyprus", "czech-republic", "denmark", "estonia", "faroe-islands", "finland", "france", "georgia", "germany", "great-britain", "greece", "hungary", "iceland", "ireland-and-northern-ireland", "isle-of-man", "italy", "kosovo", "latvia", "liechtenstein", "lithuania", "luxembourg", "macedonia", "malta", "moldova", "monaco", "montenegro", "netherlands", "norway", "poland", "portugal", "romania", "russia-european-part", "serbia", "slovakia", "slovenia", "spain", "sweden", "switzerland", "turkey", "ukraine", "alps", "british-isles", "dach"], "central-america": ["belize", "cuba", "guatemala", "haiti-and-domrep", "nicaragua"], "antartica": [], "north-america": ["canada", "greenland", "mexico", "us-midwest", "us-northeast", "us-pacific", "us-south", "us-west"], "africa": ["benin", "botswana", "burkina-faso", "cameroon", "canary-islands", "congo-democratic-republic", "egypt", "ethiopia", "guinea", "guinea-bissau", "ivory-coast", "kenya", "lesotho", "liberia", "libya", "madagascar", "morocco", "nigeria", "sierra-leone", "somalia", "south-africa-and-lesotho", "tanzania"], "asia": ["azerbaijan", "bangladesh", "china", "gcc-states", "india", "indonesia", "iran", "iraq", "israel-and-palestine", "japan", "jordan", "kazakhstan", "kyrgyzstan", "lebanon", "malaysia-singapore-brunei", "mongolia", "nepal", "north-korea", "pakistan", "philippines", "russia-asian-part", "south-korea", "sri-lanka", "syria", "taiwan", "tajikistan", "thailand", "turkmenistan", "uzbekistan", "vietnam"], "australia-oceania": ["australia", "fiji", "new-caledonia", "new-zealand"], "south-america": ["argentina", "bolivia", "brazil", "chile", "colombia", "ecuador", "paraguay", "peru", "uruguay"]} \ No newline at end of file diff --git a/downloader.py b/downloader.py new file mode 100644 index 0000000..c782f84 --- /dev/null +++ b/downloader.py @@ -0,0 +1,57 @@ +#!/usr/bin/python + +import sys +from json import loads +from subprocess import call + +URL = 'http://download.geofabrik.de/' + +if len(sys.argv) < 2: + print 'Not enough argument. "list" or a name (continent or country)' + exit() + +# The JSON file comes from https://gist.github.com/Gustry/4e14bf096cdec09a3e57 +json_data = open('countries.json').read() +data = loads(json_data) + +if sys.argv[1] == 'list': + for continent, countries in data.items(): + print continent + for country in countries: + print ' ' + country + exit() +else: + area = sys.argv[1] + url = None + for continent, countries in data.items(): + if area == continent: + url = URL + area + else: + if area in countries: + url = URL + continent + '/' + area + +if url: + poly_file = url + '.poly' + pbf_file = url + '-latest.osm.pbf' + diff = url + '-updates/' + state = diff + 'state.txt' + print 'Polygon file : ' + poly_file + print 'PBF file : ' + pbf_file + print 'Diff (not used): ' + diff + print 'state : ' + state + + print 'Downloading PBF' + commands = ['wget', '-c', '-O', 'osm_pbf/country.pbf', pbf_file] + call(commands) + + print 'Downloading polygon' + commands = ['wget', '-c', '-O', 'osm_pbf/country.poly', poly_file] + call(commands) + + print 'Downloading state' + commands = ['wget', '-c', '-O', 'osm_pbf/country.state.txt', state] + call(commands) + +else: + print 'This area is unkown in geofabrik or in our script. Check with the list argument.' +