From a45480e6613723c3f8112a8f8b4523cd6ab2cf15 Mon Sep 17 00:00:00 2001 From: Antonio Lima Date: Thu, 19 May 2016 11:28:46 +0100 Subject: [PATCH] Working --- overpass/api.py | 9 ++++++--- overpass/cli.py | 7 +++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/overpass/api.py b/overpass/api.py index a19209a4f15..1e0cd6ff752 100644 --- a/overpass/api.py +++ b/overpass/api.py @@ -13,7 +13,7 @@ class API(object): # defaults for the API class _timeout = 25 # seconds _endpoint = "http://overpass-api.de/api/interpreter" - _debug = False + _debug = True _QUERY_TEMPLATE = "[out:{out}];{query}out {verbosity};" _GEOJSON_QUERY_TEMPLATE = "[out:json];{query}out body geom;" @@ -35,11 +35,14 @@ def __init__(self, *args, **kwargs): requests_log.setLevel(logging.DEBUG) requests_log.propagate = True - def Get(self, query, responseformat="geojson", verbosity="body"): + def Get(self, query, responseformat="geojson", verbosity="body", build=True): """Pass in an Overpass query in Overpass QL""" # Construct full Overpass query - full_query = self._ConstructQLQuery(query, responseformat=responseformat, verbosity=verbosity) + if build: + full_query = self._ConstructQLQuery(query, responseformat=responseformat, verbosity=verbosity) + else: + full_query = query # Get the response from Overpass raw_response = self._GetFromOverpass(full_query) diff --git a/overpass/cli.py b/overpass/cli.py index 28bb0267286..cc85d1ca100 100644 --- a/overpass/cli.py +++ b/overpass/cli.py @@ -12,8 +12,9 @@ help='URL of your prefered API.') @click.option('--responseformat', default='geojson', help="""Format to save the data. Options are 'geojson' and 'osm'. Default format is geojson.""") +@click.option('-q', '--queryfile', type=click.File("r")) @click.argument('query', type=str) -def cli(timeout, endpoint, responseformat, query): +def cli(timeout, endpoint, responseformat, query, queryfile): """Run query""" api = overpass.API(timeout=timeout, endpoint=endpoint) if responseformat not in api.SUPPORTED_FORMATS: @@ -21,5 +22,7 @@ def cli(timeout, endpoint, responseformat, query): responseformat, ", ".join(api.SUPPORTED_FORMATS))) sys.exit(1) - result = api.Get(query, responseformat=responseformat) + if queryfile: + query = queryfile.read() + result = api.Get(query, responseformat=responseformat, build=not bool(queryfile)) click.echo(result) \ No newline at end of file