cleanup, proper handling of ignore_ids
This commit is contained in:
18
osmsearch.py
18
osmsearch.py
@@ -20,6 +20,7 @@ class OSMSearch():
|
||||
self.maxsearchnums = args.pop("maxsearchnums")
|
||||
self.gpxfilename = args.pop("outputfilename")
|
||||
self.use_boundingbox = args.pop("use_boundingbox")
|
||||
self.ignore_ids = args.pop("ignore_ids")
|
||||
if self.use_boundingbox:
|
||||
assert isinstance(list, args["boundingbox"])
|
||||
assert len(args["boundingbox"]) == 4
|
||||
@@ -36,11 +37,13 @@ class OSMSearch():
|
||||
|
||||
def initialize_gpx_file(self):
|
||||
if os.path.isfile(self.gpxfilename):
|
||||
# open file and parse
|
||||
#if verbosity > 0: print(f"found file, extending")
|
||||
self.gpxfile = gpxpy.parse(open(gpxfilename, "r"))
|
||||
raise NotImplementedError("We don't know how to deal with existing files yet, sry")
|
||||
# TODO: file name collision? either:
|
||||
# 1) amend file
|
||||
#self.gpxfile = gpxpy.parse(open(gpxfilename, "r"))
|
||||
# 2) refuse to work
|
||||
# 3) alter file name
|
||||
else:
|
||||
#if verbosity > 0: print("creating new file")
|
||||
self.gpxfile = gpxpy.gpx.GPX()
|
||||
|
||||
def get_argstring(self):
|
||||
@@ -48,6 +51,8 @@ class OSMSearch():
|
||||
|
||||
if self.use_boundingbox:
|
||||
argstring.append(",".join(list(map(str, self.searchargs["boundingbox"]))))
|
||||
if self.ignore_ids != []:
|
||||
argstrings.append(f"ignore_ids=" + ",".join(list(map(str, self.ignore_ids))))
|
||||
for arg in self.searchargs:
|
||||
argstrings.append(f"{arg}={self.searchargs[arg]}")
|
||||
|
||||
@@ -63,24 +68,21 @@ class OSMSearch():
|
||||
r = requests.get(self.url + self.get_argstring())
|
||||
|
||||
if r.status_code != 200:
|
||||
#if verbosity > 0: print(f"Query gone wrong: HTTP returned {r.status_code}")
|
||||
exit(1)
|
||||
|
||||
# parse reply
|
||||
reply = r.json()
|
||||
assert isinstance(reply, list), "Unexpected type of reply: " + type(reply)
|
||||
if len(reply) == 0:
|
||||
if verbosity > 0: print(f"found {len(ignore_ids)} results in {i-1} iterations, finishing")
|
||||
break
|
||||
|
||||
for point in reply:
|
||||
self.searchargs["ignore_ids"].append(point["place_id"])
|
||||
self.ignore_ids.append(point["place_id"])
|
||||
self.gpxfile.waypoints.append(gpxpy.gpx.GPXWaypoint(latitude=point["lat"], longitude=point["lon"], name=point["display_name"]))
|
||||
|
||||
def save_to_disk(self):
|
||||
with open(self.gpxfilename, "w") as f:
|
||||
f.write(self.gpxfile.to_xml())
|
||||
#if verbosity > 0: print(f"GPX file written to {gpxfilename}")
|
||||
|
||||
default_args = {
|
||||
"q": "Camping",
|
||||
|
||||
Reference in New Issue
Block a user