22from __future__ import print_function
33import click
44import geojson
5-
5+ import sys
66import overpass
77
88
1313@click .option ('--responseformat' , default = 'geojson' , help = """Format to save the data.
1414 Options are 'geojson' and 'osm'. Default format is geojson.""" )
1515@click .argument ('query' , type = str )
16- @click .argument ('output_file' , type = click .Path ())
17- def cli (timeout , endpoint , responseformat , query , output_file ):
18- """Run query and save the result in output_file"""
19-
16+ def cli (timeout , endpoint , responseformat , query ):
17+ """Run query"""
2018 api = overpass .API (timeout = timeout , endpoint = endpoint )
21-
2219 if responseformat not in api .SUPPORTED_FORMATS :
2320 print ("format {} not supported. Supported formats: {}" .format (
2421 responseformat ,
25- api .SUPPORTED_FORMATS .join (", " )))
22+ ", " .join (api .SUPPORTED_FORMATS )))
23+ sys .exit (1 )
2624 result = api .Get (query , responseformat = responseformat )
27- with open (output_file , 'w' ) as f :
28- if responseformat == "geojson" :
29- geojson .dump (result , f , indent = 2 , sort_keys = True )
30- else :
31- f .write (result .encode ('utf-8' ))
32- f .close ()
33- print ('File saved at %s.' % output_file )
25+ click .echo (result )
0 commit comments