owm.py: check for w['rain']['3h'] master
authorgregor herrmann <gregor@toastfreeware.priv.at>
Sun, 30 Aug 2020 14:54:20 +0000 (16:54 +0200)
committergregor herrmann <gregor@toastfreeware.priv.at>
Sun, 30 Aug 2020 14:54:20 +0000 (16:54 +0200)
The missing rain key was checked but sometimes we get the rain but only the 1h interval.

owm.py
seewasser.py

diff --git a/owm.py b/owm.py
index 74fe6c4..d97d57e 100755 (executable)
--- a/owm.py
+++ b/owm.py
@@ -52,7 +52,7 @@ def extractweatherdata(w):
 
     data['winddegrees'] = w['wind']['deg'] if 'deg' in w['wind'] else math.nan
     data['winddirection'] = degToCompass(data['winddegrees'])
-    data['precipitation'] = w['rain']['3h'] if 'rain' in w else math.nan
+    data['precipitation'] = w['rain']['3h'] if 'rain' in w and w['rain'].get('3h') else math.nan
     data['visibility'] = w.get('visibility', math.nan)
 
     return data
index 5bf2ce2..922a990 100755 (executable)
@@ -12,6 +12,8 @@ from sqlalchemy import create_engine
 import warnings
 import MySQLdb.cursors
 
+logging.basicConfig(format='%(levelname)s: %(message)s', level=logging.INFO)
+
 #May 27 21:32 /sys/bus/w1/devices/28-0416a1bab9ff
 #May 27 21:33 /sys/bus/w1/devices/28-0416a1ac66ff
 #May 27 21:35 /sys/bus/w1/devices/28-0516a207a4ff
@@ -109,7 +111,8 @@ def main(configfile, fromcsvfile):
         timestamp, value_raw, value = readsensor(sensor_id)
         writesensordatacsv(config, sensor_id, sensor_name, timestamp, value_type, value_raw, value)
         writesensordatadb(config, sensor_id, sensor_name, timestamp, value_type, value_raw, value)
-        logging.info('Sensor {}: {:.1f}°C'.format(sensor_id, value))
+        if args.verbose:
+            logging.info('Sensor {}: {:.1f}°C'.format(sensor_id, value))
 
 
 if __name__ == '__main__':