diff --git a/index.html b/index.html index 9c21b53..d490a85 100644 --- a/index.html +++ b/index.html @@ -13,10 +13,10 @@ This form allows you to perform a search of the Open Street Map database (via Nominatim) and exports all results as Waypoints in a GPX file. -
+ Your search query
- (optional)
- (optional)
+ (optional)
+ (optional)
(optional)

diff --git a/websearch.py b/websearch.py new file mode 100755 index 0000000..a7837d9 --- /dev/null +++ b/websearch.py @@ -0,0 +1,61 @@ +#!/usr/bin/python +""" +CGI interface to osmsearch.py +""" + +__author__ = "fordprefect" +__date__ = "2020-03-26" +__version__ = "0.1" +print("Content-type: text/html\n") # makes sure the http connection does not die - do nothing before this! + +import cgi +import pathvalidate +import osmsearch +import sys +assert sys.version_info >= (3, 6), "At least Python 3.8 required due to fStrings. Replace all f\"…\" and comment this line to enable running in lower versions (but really, you should just update your Python version…)." + +##################################### +######## configuration +##################################### + +# default set of arguments +args = { + "q": "Camping", + "format": "json", + "limit": 50, + "use_boundingbox": False, + "boundingbox": [], + "outputfilename": None, + "ignore_ids": [], + "maxsearchnums": 10, + "url": "https://nominatim.openstreetmap.org/search/", +} +immutable_args = ["format", "outputfilename", "url",] + +##################################### +######## end of configuration +##################################### + +def get_arguments(): + """Wrapper for cgi-environment. + Takes no options, returns dict of arguments + """ + args = cgi.FieldStorage() + return {i: args.getvalue(i) for i in args} + +# get cgi args and sanitize +cgi_args = get_arguments() +parsed_args = {} +try: + cgi_args["q"] = pathvalidate.sanitize_filename(cgi_args["query"]) +except KeyError: + # no key called "query" found, abort + exit() +for arg in cgi_args: + if arg not in immutable_args and arg in args: + parsed_args[arg] = cgi_args[arg] +print(parsed_args, " parsed") + +args.update(cgi_args) + +#status = osmsearch.conduct_search(args)