-#!/usr/bin/python3.4
import re
import xml.dom.minidom as minidom
from xml.parsers.expat import ExpatError
from enum import IntEnum
-from flask import request, redirect, url_for, flash
-from wradmin.genshi import render_genshi_template, TemplateContext
+from flask import request, redirect, url_for, flash, render_template
class MultiGeo(IntEnum):
result = []
for line in lines:
if input_format == MultiGeo.FORMAT_GUESS or input_format == MultiGeo.FORMAT_GEOCACHING:
- r = re.match('N ?(\d+)° ?(\d+\.\d+) +E ?(\d+)° ?(\d+\.\d+)', line)
+ r = re.match(r'N ?(\d+)° ?(\d+\.\d+) +E ?(\d+)° ?(\d+\.\d+)', line)
if r is not None:
g = r.groups()
result.append((float(g[0]) + float(g[1]) / 60, float(g[2]) + float(g[3]) / 60, None))
continue
if input_format == MultiGeo.FORMAT_GUESS or input_format == MultiGeo.FORMAT_WINTERRODELN:
- r = re.match('(\d+\.\d+) N (\d+\.\d+) E', line)
+ r = re.match(r'(\d+\.\d+) N (\d+\.\d+) E', line)
if not r is None:
result.append((float(r.groups()[0]), float(r.groups()[1]), None))
continue
if input_format == MultiGeo.FORMAT_GUESS or input_format == MultiGeo.FORMAT_GMAPPLUGIN:
- r = re.match('(\d+\.\d+), ?(\d+\.\d+)', line)
+ r = re.match(r'(\d+\.\d+), ?(\d+\.\d+)', line)
if r is not None:
result.append((float(r.groups()[0]), float(r.groups()[1]), None))
continue
result.append('%.6f, %.6f' % (latitude, longitude))
elif output_format == MultiGeo.FORMAT_GPX:
- if not height is None:
+ if height is not None:
result.append(
'<trkpt lat="%.6f" lon="%.6f"><ele>%.2f</ele></trkpt>' % (latitude, longitude, height))
else:
class CoordtoolController:
def index(self):
- c = TemplateContext()
- c.result = None
- return render_genshi_template('coordtool.html', c=c)
+ return render_template('coordtool.html', result=None)
def convert(self):
- c = TemplateContext()
assert request.method == 'POST'
input = request.form['input']
no_elevation = 'no_elevation' in request.form
simplify = 'simplify' in request.form
swap_latlon = 'swap_latlon' in request.form
- c.no_geoformat = 'no_geoformat' in request.form
- c.no_gpxformat = 'no_gpxformat' in request.form
- c.no_gmapsformat = 'no_gmapsformat' in request.form
- c.no_geocachingformat = 'no_geocachingformat' in request.form
+ no_geoformat = 'no_geoformat' in request.form
+ no_gpxformat = 'no_gpxformat' in request.form
+ no_gmapsformat = 'no_gmapsformat' in request.form
+ no_geocachingformat = 'no_geocachingformat' in request.form
if input is None or len(input.strip()) == 0:
- c.result = None
return redirect(url_for('coordtool_index'))
try:
- c.result = multigeo_from_string(input, MultiGeo.FORMAT_GUESS)
+ result = multigeo_from_string(input, MultiGeo.FORMAT_GUESS)
except ValueError as e:
flash(str(e))
return redirect(url_for('coordtool_index'))
if swap_latlon:
- c.result = [(latitude, longitude, elevation) for (longitude, latitude, elevation) in c.result]
+ result = [(latitude, longitude, elevation) for (longitude, latitude, elevation) in result]
if no_elevation:
- c.result = [(longitude, latitude, None) for (longitude, latitude, elevation) in c.result]
+ result = [(longitude, latitude, None) for (longitude, latitude, elevation) in result]
- c.geo_winterrodeln = lambda value: multigeo_to_string(value, MultiGeo.FORMAT_WINTERRODELN)
- c.geo_gmapplugin = lambda value: multigeo_to_string(value, MultiGeo.FORMAT_GMAPPLUGIN)
- c.geo_gpx = lambda value: multigeo_to_string(value, MultiGeo.FORMAT_GPX)
- c.geo_geocaching = lambda value: multigeo_to_string(value, MultiGeo.FORMAT_GEOCACHING)
+ geo_winterrodeln = lambda value: multigeo_to_string(value, MultiGeo.FORMAT_WINTERRODELN)
+ geo_gmapplugin = lambda value: multigeo_to_string(value, MultiGeo.FORMAT_GMAPPLUGIN)
+ geo_gpx = lambda value: multigeo_to_string(value, MultiGeo.FORMAT_GPX)
+ geo_geocaching = lambda value: multigeo_to_string(value, MultiGeo.FORMAT_GEOCACHING)
- return render_genshi_template('coordtool.html', c=c)
+ return render_template('coordtool.html', result=result,
+ no_geoformat=no_geoformat, geo_winterrodeln=geo_winterrodeln,
+ no_gmapsformat=no_gmapsformat, geo_gmapplugin=geo_gmapplugin,
+ no_gpxformat=no_gpxformat, geo_gpx=geo_gpx,
+ no_geocachingformat=no_geocachingformat, geo_geocaching=geo_geocaching)