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
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/
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/<int:timespan>", methods=['GET'])
def data(timespan):
@app.route("/")
def index():
- return render_template('seepark_web.html')
+ return render_template('seepark_web.html', apikey=apikey)
border: 1px solid;
}
-#buttonbar {
+#buttonbar, #openweathermap-widget-15 {
margin: 0 auto;
text-align: center;
padding-top: 1em;
}
+
+#openweathermap-widget-15 {
+ width: 300px;
+}
<button onclick="loaddays(365)">Jahr</button>
</div>
+ <!-- openweathermap widget -->
+ <div id="openweathermap-widget-15"></div>
+ <script>
+ window.myWidgetParam ? window.myWidgetParam : window.myWidgetParam = [];
+ window.myWidgetParam.push({
+ id: 15,
+ cityid: '3319578',
+ appid: '{{ apikey }}',
+ units: 'metric',
+ containerid: 'openweathermap-widget-15',
+ lang: 'de',
+ });
+ (function() {
+ var script = document.createElement('script');
+ script.async = true;
+ script.charset = "utf-8";
+ script.src = "//openweathermap.org/themes/openweathermap/assets/vendor/owm/js/weather-widget-generator.js";
+ var s = document.getElementsByTagName('script')[0];
+ s.parentNode.insertBefore(script, s);
+ })();
+ </script>
+
<!-- Load own javascript code -->
<script src="{{url_for('static', filename='seepark_web.js')}}"></script>