62 lines
1.6 KiB
Python
Executable File
62 lines
1.6 KiB
Python
Executable File
#!/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)
|