From: Philipp Spitzer Date: Wed, 1 Aug 2018 21:12:00 +0000 (+0200) Subject: The air temperature is taken from the database now. X-Git-Url: https://git.toastfreeware.priv.at/chrisu/seepark.git/commitdiff_plain/6acfad15e0f6ec9f864a1cf53680f3500f42ff21 The air temperature is taken from the database now. --- diff --git a/web/seepark_web.py b/web/seepark_web.py index 03d5760..a6d3930 100644 --- a/web/seepark_web.py +++ b/web/seepark_web.py @@ -180,13 +180,9 @@ def openweathermapdata(cityid): return result -def currentairtemperature(apikey, cityid): - """Retruns the tuple temperature, datetime (as float, datetime) in case of success, otherwise None, None.""" - try: - url, weatherdata = openweathermap_json(apikey, cityid) - return weatherdata['main']['temp'], datetime.datetime.fromtimestamp(weatherdata['dt']) - except OpenWeatherMapError: - return None, None +def currentairtemperature(cityid): + result = OpenWeatherMap.query.filter_by(cityid=cityid).order_by(OpenWeatherMap.datetime.desc()).first() + return result.temp, result.datetime def currentwatertemperature(sensorid): @@ -275,7 +271,7 @@ def data(timespan): @app.route("/") def index(): - airvalue, airtime = currentairtemperature(apikey, cityid) + airvalue, airtime = currentairtemperature(cityid) watervalue, watertime = currentwatertemperature(mainsensor) return render_template(