-
Notifications
You must be signed in to change notification settings - Fork 26
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 #12 from interline-io/download-extracts
Refactoring and osm_extract_download
- Loading branch information
Showing
11 changed files
with
126 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"python.pythonPath": "${workspaceFolder}/virtualenv/bin/python" | ||
} |
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,31 @@ | ||
import os | ||
import subprocess | ||
import log | ||
|
||
def download(url, outpath): | ||
pass | ||
|
||
def download_gzip(url, outpath): | ||
with open(outpath, 'wb') as f: | ||
ps1 = subprocess.Popen(['curl', '-L', '--fail', '-s', url], stdout=subprocess.PIPE) | ||
ps2 = subprocess.Popen(['gzip', '-d'], stdin=ps1.stdout, stdout=f) | ||
ps2.wait() | ||
|
||
def download_curl(url, outpath, compressed=False): | ||
if os.path.exists(outpath): | ||
log.warning("Warning: output path %s already exists."%outpath) | ||
args = ['curl', '-L', '--fail', '-o', outpath, url] | ||
if not compressed: | ||
args.append('--compressed') | ||
|
||
log.info("Downloading to %s"%outpath) | ||
log.debug(url) | ||
log.debug(' '.join(args)) | ||
p = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
out, err = p.communicate() | ||
e = p.wait() | ||
if e != 0: | ||
raise Exception("Error downloading: %s"%err.split("curl:")[-1]) | ||
else: | ||
log.info("Done") | ||
|
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,33 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import argparse | ||
|
||
import log | ||
from bbox import bbox_string, load_bboxes_csv | ||
from osm_extract_downloader import OsmExtractDownloader | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser(usage="OSM Extract Download tool.") | ||
parser.add_argument('id', help='Extract ID') | ||
# parser.add_argument('--osm-extract-version', help='OSM Extract version', default='latest') | ||
parser.add_argument('--outpath', help='Output path for Extract; default is <name>.osm.pbf') | ||
parser.add_argument('--api-token', help='Interline Auth Token; default is read from $INTERLINE_API_TOKEN') | ||
parser.add_argument('--verbose', help="Verbose output", action='store_true') | ||
args = parser.parse_args() | ||
|
||
if args.verbose: | ||
log.set_verbose() | ||
|
||
outpath = args.outpath or "%s.osm.pbf"%(args.id) | ||
if os.path.exists(outpath): | ||
log.warning("Warning: output path %s already exists."%outpath) | ||
|
||
downloader = OsmExtractDownloader() | ||
downloader.download( | ||
outpath, | ||
osm_extract_id=args.id, | ||
api_token=args.api_token or os.getenv('INTERLINE_API_TOKEN') | ||
) | ||
|
||
if __name__ == '__main__': | ||
main() |
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 urllib | ||
import urlparse | ||
import subprocess | ||
import json | ||
import urllib2 | ||
|
||
import log | ||
import download | ||
|
||
class OsmExtractDownloader(object): | ||
HOST = 'https://app.interline.io' | ||
def download(self, outpath, osm_extract_id, osm_extract_version='latest', api_token=None): | ||
# Endpoint | ||
url = '%s/osm_extracts/%s/download'%(self.HOST, osm_extract_version) | ||
if osm_extract_version == 'latest': | ||
url = '%s/osm_extracts/download_latest'%(self.HOST) | ||
|
||
# Make url | ||
u = list(urlparse.urlsplit(url)) | ||
q = urlparse.parse_qs(u[3]) | ||
if osm_extract_version == "latest": | ||
q['string_id'] = osm_extract_id | ||
if api_token: | ||
q['api_token'] = api_token | ||
u[3] = urllib.urlencode(q) | ||
url = urlparse.urlunsplit(u) | ||
|
||
# Download | ||
download.download_curl(url, outpath) |
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 |
---|---|---|
|
@@ -9,26 +9,26 @@ | |
long_description = f.read() | ||
|
||
setup(name='interline-planetutils', | ||
version='0.2.8-rc1', | ||
version='0.3.0', | ||
description='Interline PlanetUtils', | ||
long_description=long_description, | ||
url='https://github.com/interline-io/planetutils', | ||
author='Ian Rees', | ||
author_email='[email protected]', | ||
license='MIT', | ||
packages=find_packages(exclude=['contrib', 'docs', 'tests']), | ||
install_requires=['boto3'], | ||
install_requires=['requests','boto3'], | ||
tests_require=['nose'], | ||
test_suite = 'nose.collector', | ||
entry_points={ | ||
'console_scripts': [ | ||
'osm_planet_update=planetutils.osm_planet_update:main', | ||
'osm_planet_extract=planetutils.osm_planet_extract:main', | ||
'osm_planet_get_timestamp=planetutils.osm_planet_get_timestamp:main', | ||
'osm_extract_download=planetutils.osm_extract_download:main', | ||
'elevation_tile_download=planetutils.elevation_tile_download:main', | ||
'valhalla_tilepack_download=planetutils.tilepack_download:main', | ||
'valhalla_tilepack_list=planetutils.tilepack_list:main' | ||
|
||
], | ||
}, | ||
classifiers=[ | ||
|
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