more saving options (stdout, return)
This commit is contained in:
17
osmsearch.py
17
osmsearch.py
@@ -16,9 +16,15 @@ assert sys.version_info >= (3, 6), "At least Python 3.8 required due to fStrings
|
|||||||
|
|
||||||
class OSMSearch():
|
class OSMSearch():
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
|
"""
|
||||||
|
TODO: write docstring
|
||||||
|
"""
|
||||||
self.url = args.pop("url")
|
self.url = args.pop("url")
|
||||||
self.maxsearchnums = args.pop("maxsearchnums")
|
self.maxsearchnums = args.pop("maxsearchnums")
|
||||||
|
self.save_to_file = True if args["output"] == "disk" else False
|
||||||
|
if self.save_to_file:
|
||||||
self.gpxfilename = args.pop("outputfilename")
|
self.gpxfilename = args.pop("outputfilename")
|
||||||
|
self.print_xml = True if args["output"] == "print" else False
|
||||||
self.use_boundingbox = args.pop("use_boundingbox")
|
self.use_boundingbox = args.pop("use_boundingbox")
|
||||||
if self.use_boundingbox:
|
if self.use_boundingbox:
|
||||||
assert isinstance(list, args["boundingbox"])
|
assert isinstance(list, args["boundingbox"])
|
||||||
@@ -32,9 +38,16 @@ class OSMSearch():
|
|||||||
|
|
||||||
self.search()
|
self.search()
|
||||||
|
|
||||||
|
if self.save_to_file:
|
||||||
self.save_to_disk()
|
self.save_to_disk()
|
||||||
|
if self.print_xml:
|
||||||
|
self.print_to_stdout()
|
||||||
|
|
||||||
def initialize_gpx_file(self):
|
def initialize_gpx_file(self):
|
||||||
|
if not self.save_to_file:
|
||||||
|
self.gpxfile = gpxpy.gpx.GPX()
|
||||||
|
return
|
||||||
|
|
||||||
if os.path.isfile(self.gpxfilename):
|
if os.path.isfile(self.gpxfilename):
|
||||||
# open file and parse
|
# open file and parse
|
||||||
#if verbosity > 0: print(f"found file, extending")
|
#if verbosity > 0: print(f"found file, extending")
|
||||||
@@ -82,6 +95,9 @@ class OSMSearch():
|
|||||||
f.write(self.gpxfile.to_xml())
|
f.write(self.gpxfile.to_xml())
|
||||||
#if verbosity > 0: print(f"GPX file written to {gpxfilename}")
|
#if verbosity > 0: print(f"GPX file written to {gpxfilename}")
|
||||||
|
|
||||||
|
def print_to_stdout(self):
|
||||||
|
print(self.gpxfile.to_xml())
|
||||||
|
|
||||||
default_args = {
|
default_args = {
|
||||||
"q": "Camping",
|
"q": "Camping",
|
||||||
"format": "json",
|
"format": "json",
|
||||||
@@ -92,6 +108,7 @@ default_args = {
|
|||||||
"ignore_ids": [],
|
"ignore_ids": [],
|
||||||
"maxsearchnums": 10,
|
"maxsearchnums": 10,
|
||||||
"url": "https://nominatim.openstreetmap.org/search/",
|
"url": "https://nominatim.openstreetmap.org/search/",
|
||||||
|
"output": "print",
|
||||||
}
|
}
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user