The air temperature is taken from the database now.
authorPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 1 Aug 2018 21:12:00 +0000 (23:12 +0200)
committerPhilipp Spitzer <philipp@spitzer.priv.at>
Wed, 1 Aug 2018 21:12:00 +0000 (23:12 +0200)
web/seepark_web.py

index 03d5760f5e3eb9eebb8d9af62d780864e78d6540..a6d39302553bcd17f052b6cbde606473a81b9fd0 100644 (file)
@@ -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(