Skip to content
This repository was archived by the owner on Jun 10, 2025. It is now read-only.

Commit a45480e

Browse files
committed
Working
1 parent 7b273dd commit a45480e

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

overpass/api.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class API(object):
1313
# defaults for the API class
1414
_timeout = 25 # seconds
1515
_endpoint = "http://overpass-api.de/api/interpreter"
16-
_debug = False
16+
_debug = True
1717

1818
_QUERY_TEMPLATE = "[out:{out}];{query}out {verbosity};"
1919
_GEOJSON_QUERY_TEMPLATE = "[out:json];{query}out body geom;"
@@ -35,11 +35,14 @@ def __init__(self, *args, **kwargs):
3535
requests_log.setLevel(logging.DEBUG)
3636
requests_log.propagate = True
3737

38-
def Get(self, query, responseformat="geojson", verbosity="body"):
38+
def Get(self, query, responseformat="geojson", verbosity="body", build=True):
3939
"""Pass in an Overpass query in Overpass QL"""
4040

4141
# Construct full Overpass query
42-
full_query = self._ConstructQLQuery(query, responseformat=responseformat, verbosity=verbosity)
42+
if build:
43+
full_query = self._ConstructQLQuery(query, responseformat=responseformat, verbosity=verbosity)
44+
else:
45+
full_query = query
4346

4447
# Get the response from Overpass
4548
raw_response = self._GetFromOverpass(full_query)

overpass/cli.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@
1212
help='URL of your prefered API.')
1313
@click.option('--responseformat', default='geojson', help="""Format to save the data.
1414
Options are 'geojson' and 'osm'. Default format is geojson.""")
15+
@click.option('-q', '--queryfile', type=click.File("r"))
1516
@click.argument('query', type=str)
16-
def cli(timeout, endpoint, responseformat, query):
17+
def cli(timeout, endpoint, responseformat, query, queryfile):
1718
"""Run query"""
1819
api = overpass.API(timeout=timeout, endpoint=endpoint)
1920
if responseformat not in api.SUPPORTED_FORMATS:
2021
print("format {} not supported. Supported formats: {}".format(
2122
responseformat,
2223
", ".join(api.SUPPORTED_FORMATS)))
2324
sys.exit(1)
24-
result = api.Get(query, responseformat=responseformat)
25+
if queryfile:
26+
query = queryfile.read()
27+
result = api.Get(query, responseformat=responseformat, build=not bool(queryfile))
2528
click.echo(result)

0 commit comments

Comments
 (0)