From: gregor herrmann Date: Fri, 8 Jun 2018 21:51:18 +0000 (+0200) Subject: add an openweathermap widget to the webpage X-Git-Url: https://git.toastfreeware.priv.at/chrisu/seepark.git/commitdiff_plain/97dea911176a579b4e927ba7f575bdb2d4438fc7 add an openweathermap widget to the webpage more of a gimmick ... the api key is read from the ini file passed via SEEPARKINI (and not via flask's config mechanism as this expects a python file) fun fact: the api key will appear in the javaescript in the page anyway --- diff --git a/web/README b/web/README index 7458e9f..19ec585 100644 --- a/web/README +++ b/web/README @@ -1,7 +1,7 @@ Needed package: python3-flask Start with: -FLASK_APP=seepark_web.py FLASK_DEBUG=1 flask run +FLASK_APP=seepark_web.py FLASK_DEBUG=1 SEEPARKINI=~/seewasser.ini flask run Go to: http://127.0.0.1:5000/ diff --git a/web/seepark_web.py b/web/seepark_web.py index fa08f12..5263174 100644 --- a/web/seepark_web.py +++ b/web/seepark_web.py @@ -1,8 +1,14 @@ from flask import Flask, render_template, jsonify from random import uniform import time +import configparser +import os app = Flask(__name__) +config = configparser.ConfigParser() +config.read(os.environ['SEEPARKINI']) +apikey = config.get('openweathermap', 'apikey'); + @app.route('/data/', defaults={'timespan': 1}) @app.route("/data/", methods=['GET']) def data(timespan): @@ -36,5 +42,5 @@ def data(timespan): @app.route("/") def index(): - return render_template('seepark_web.html') + return render_template('seepark_web.html', apikey=apikey) diff --git a/web/static/seepark_web.css b/web/static/seepark_web.css index 5cf1aad..6ddd30a 100644 --- a/web/static/seepark_web.css +++ b/web/static/seepark_web.css @@ -21,8 +21,12 @@ button { border: 1px solid; } -#buttonbar { +#buttonbar, #openweathermap-widget-15 { margin: 0 auto; text-align: center; padding-top: 1em; } + +#openweathermap-widget-15 { + width: 300px; +} diff --git a/web/templates/seepark_web.html b/web/templates/seepark_web.html index 746e9a5..4d136e3 100644 --- a/web/templates/seepark_web.html +++ b/web/templates/seepark_web.html @@ -25,6 +25,28 @@ + +
+ +