Skip to content

Commit

Permalink
Working
Browse files Browse the repository at this point in the history
  • Loading branch information
themiurgo committed May 19, 2016
1 parent 7b273dd commit a45480e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
9 changes: 6 additions & 3 deletions overpass/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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;"
Expand All @@ -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)
Expand Down
7 changes: 5 additions & 2 deletions overpass/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@
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:
print("format {} not supported. Supported formats: {}".format(
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)

0 comments on commit a45480e

Please sign in to comment.