gpx file download done properly
This commit is contained in:
42
websearch.py
42
websearch.py
@@ -16,6 +16,7 @@ import random
|
|||||||
import os
|
import os
|
||||||
import sys
|
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…)."
|
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…)."
|
||||||
|
import base64
|
||||||
|
|
||||||
#####################################
|
#####################################
|
||||||
######## configuration
|
######## configuration
|
||||||
@@ -71,7 +72,7 @@ args["outputfilename"] = outputfilename
|
|||||||
|
|
||||||
searchresult = osmsearch.OSMSearch(args)
|
searchresult = osmsearch.OSMSearch(args)
|
||||||
gpxcontent = searchresult.gpxfile.to_xml()
|
gpxcontent = searchresult.gpxfile.to_xml()
|
||||||
gpxcontent_escaped = searchresult.gpxfile.to_xml().replace("\\", "\\\\").replace("'", "\\'").replace('"', '\\"')
|
gpxcontent_base64 = base64.b64encode(gpxcontent.encode("utf-8")).decode("utf-8")
|
||||||
|
|
||||||
print("""
|
print("""
|
||||||
<html>
|
<html>
|
||||||
@@ -80,20 +81,6 @@ print("""
|
|||||||
<link rel="stylesheet" type="text/css" href="style.css">
|
<link rel="stylesheet" type="text/css" href="style.css">
|
||||||
<meta name="robots" content="noindex,nofollow" />
|
<meta name="robots" content="noindex,nofollow" />
|
||||||
<title>OSM search to GPX</title>
|
<title>OSM search to GPX</title>
|
||||||
<script type='text/javascript'>
|
|
||||||
function download_file(filename, text) {
|
|
||||||
var element = document.createElement('a');
|
|
||||||
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
|
|
||||||
element.setAttribute('download', filename);
|
|
||||||
|
|
||||||
element.style.display = 'none';
|
|
||||||
document.body.appendChild(element);
|
|
||||||
|
|
||||||
element.click();
|
|
||||||
|
|
||||||
document.body.removeChild(element);
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
</head>
|
</head>
|
||||||
<body class=body>
|
<body class=body>
|
||||||
<div class=head>
|
<div class=head>
|
||||||
@@ -101,11 +88,11 @@ function download_file(filename, text) {
|
|||||||
</div>
|
</div>
|
||||||
<div class=box>
|
<div class=box>
|
||||||
<h4>Success</h4>
|
<h4>Success</h4>
|
||||||
Copy file content from here:
|
""" + f"""
|
||||||
<br>
|
<a href="data:text/xml;base64,{gpxcontent_base64}"
|
||||||
<textarea rows=10 cols=80 style="font-family: monospace;">"""
|
""" + """
|
||||||
+ gpxcontent +
|
download="search.gpx">Download GPX file here</a>
|
||||||
"""</textarea>
|
|
||||||
<br><br>
|
<br><br>
|
||||||
<a href=index.html>Return to search page</a>
|
<a href=index.html>Return to search page</a>
|
||||||
|
|
||||||
@@ -116,18 +103,3 @@ OSMsearchToGPX - ein Service von <a href=https://dukun.de>dukun.de</a>
|
|||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
""")
|
""")
|
||||||
# TODO download button does not work this way!
|
|
||||||
#"""</textarea>
|
|
||||||
#<br>
|
|
||||||
#or <button onclick="download_file('OSMsearch.gpx', '{gpxcontent}')">dowload here</button> (requires enabled JavaScript).
|
|
||||||
#
|
|
||||||
#<br><br>
|
|
||||||
#<a href=index.html>Return to search page</a>
|
|
||||||
#
|
|
||||||
#</div>
|
|
||||||
#<div class=foot>
|
|
||||||
#OSMsearchToGPX - ein Service von <a href=https://dukun.de>dukun.de</a>
|
|
||||||
#</div>
|
|
||||||
#</body>
|
|
||||||
#</html>
|
|
||||||
#""".format(gpxcontent=gpxcontent_escaped))
|
|
||||||
|
|||||||
Reference in New Issue
Block a user