Skip to content

Commit f9e21ab

Browse files
authored
Merge pull request #57 from themiurgo/multiline
Support for full multiline query
2 parents 68f6dfe + 01bcf44 commit f9e21ab

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

overpass/api.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -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

+7-2
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,19 @@
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('-f', '--queryasfile', help="Pass a full query as a file (useful for multiline queries).",
16+
is_flag=True)
1517
@click.argument('query', type=str)
16-
def cli(timeout, endpoint, responseformat, query):
18+
def cli(timeout, endpoint, responseformat, query, queryasfile):
1719
"""Run query"""
1820
api = overpass.API(timeout=timeout, endpoint=endpoint)
1921
if responseformat not in api.SUPPORTED_FORMATS:
2022
print("format {} not supported. Supported formats: {}".format(
2123
responseformat,
2224
", ".join(api.SUPPORTED_FORMATS)))
2325
sys.exit(1)
24-
result = api.Get(query, responseformat=responseformat)
26+
if queryasfile:
27+
queryfile = click.open_file(query, "r")
28+
query = queryfile.read()
29+
result = api.Get(query, responseformat=responseformat, build=not bool(queryasfile))
2530
click.echo(result)

0 commit comments

Comments
 (0)