diff --git a/wetter/templates/dyn/stations.js b/wetter/templates/dyn/stations.js deleted file mode 100644 index 57e1d95..0000000 --- a/wetter/templates/dyn/stations.js +++ /dev/null @@ -1,3 +0,0 @@ -{% for station in stations %} -L.marker([{{ station.lat }}, {{ station.lon }}]).addTo(mymap).bindPopup("{{ station.name }}
Mehr"); -{% endfor %} diff --git a/wetter/templates/index.html b/wetter/templates/index.html index e0ff63e..c5b4387 100644 --- a/wetter/templates/index.html +++ b/wetter/templates/index.html @@ -30,7 +30,7 @@ {% block foot %} - {% endblock %} diff --git a/wetter/templates/station.html b/wetter/templates/station.html index 3f33563..01dcf3d 100644 --- a/wetter/templates/station.html +++ b/wetter/templates/station.html @@ -56,7 +56,7 @@ {% block foot %} - {% endblock %} diff --git a/wetter/views.py b/wetter/views.py index 4f33632..bd11a2f 100644 --- a/wetter/views.py +++ b/wetter/views.py @@ -3,7 +3,7 @@ from wetter import app from wetter.models import Stations, Climate from wetter.utils import fromisoformat -from flask import request, make_response, render_template +from flask import request, make_response, render_template, jsonify from datetime import datetime @app.route('/') @@ -69,17 +69,23 @@ def export_target_dwd_txt_render(dwd_id): return r -@app.route('/dyn/stations.js') -def dyn_stations_js(): +@app.route('/api/station') +def api_station(): s = request.args.get('s') if s: station = Stations.query.filter_by(dwd_id=s).first_or_404() stations = [station] else: - stations = Stations.query.order_by(Stations.dwd_id.asc()).all() + stations = Stations.query.order_by(Stations.lon.asc()).order_by(Stations.lat.desc()).all() - r = make_response(render_template('dyn/stations.js', stations=stations)) - r.headers['Content-Type'] = 'application/javascript; charset=utf-8' + out = [] + for s in stations: + out.append({ + "name": s.name, + "lat": s.lat, + "lon": s.lon, + "dwd_id": s.dwd_id, + }) - return r + return jsonify(out)