webinterface (WIP)
This commit is contained in:
@@ -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.
|
||||
|
||||
<form action=search.py method=post>
|
||||
<form action=websearch.py method=post>
|
||||
<input name=query placeholder=Camping></input> Your search query<br>
|
||||
<input type= name=></input> (optional)<br>
|
||||
<input type= name=></input> (optional)<br>
|
||||
<input name=malicious></input> (optional)<br>
|
||||
<input name=url></input> (optional)<br>
|
||||
<input name= ></input> (optional)<br>
|
||||
<input type=submit name="Submit"><br>
|
||||
</form>
|
||||
|
||||
61
websearch.py
Executable file
61
websearch.py
Executable file
@@ -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)
|
||||
Reference in New Issue
Block a user