+def currentairtemperature(apikey, cityid):
+ baseurl = 'http://api.openweathermap.org/data/2.5/weather'
+ query = baseurl + '?units=metric&APPID={}&id={}&lang=de'.format(apikey, cityid)
+ try:
+ response = requests.get(query)
+ if response.status_code != 200:
+ response = 'N/A'
+ return response, datetime.datetime.now().strftime('%Y-%m-%d %H:%M')
+ else:
+ weatherdata = response.json()
+ return weatherdata['main']['temp'], datetime.datetime.fromtimestamp(weatherdata['dt']).strftime('%Y-%m-%d %H:%M')
+ except requests.exceptions.RequestException as error:
+ print (error)
+
+
+def currentwatertemperature(sensorid):
+ engine = open_engine(config)
+ with engine.connect() as conn:
+ cursor = conn.execute('select value, timestamp from sensors where sensor_id=%s order by timestamp desc limit 1', sensorid)
+ result = [dict(row) for row in cursor]
+ return result[0]['value'], result[0]['timestamp'].strftime('%Y-%m-%d %H:%M')
+
+