seewasser.py: add a --verbose option for the impatient
authorgregor herrmann <gregor@toastfreeware.priv.at>
Sun, 21 Apr 2019 23:08:35 +0000 (01:08 +0200)
committergregor herrmann <gregor@toastfreeware.priv.at>
Sun, 21 Apr 2019 23:08:35 +0000 (01:08 +0200)
seewasser.py

index be5f149..5bf2ce2 100755 (executable)
@@ -79,6 +79,8 @@ def writesensordatadb(config, sensor_id, sensor_name, timestamp, value_type, val
     with warnings.catch_warnings():
         # ignore _mysql_exceptions.Warning: Duplicate entry '0316a2193bff-2018-08-29 14:30:00' for key 'sensorid_timestamp'
         warnings.simplefilter("ignore", category=MySQLdb.cursors.Warning)
+        if args.verbose:
+            logging.info("Writing to database: sensor_id={}, sensor_name={}, value_type={}, value_raw={}, value={}, timestamp={}".format(sensor_id, sensor_name, value_type, value_raw, value, timestamp))
         conn.execute("insert ignore into sensors (sensor_id, sensor_name, value_type, value_raw, value, timestamp) values (%s,%s,%s,%s,%s,%s)", sensor_id, sensor_name, value_type, value_raw, value, timestamp)
     conn.close()
 
@@ -115,6 +117,7 @@ if __name__ == '__main__':
     parser = argparse.ArgumentParser(description='Read sensor data')
     parser.add_argument('--config', default=default_config_file, help='configuration file')
     parser.add_argument('--fromcsvfile', help='write values from csv file to database')
+    parser.add_argument("--verbose", help='write some output', action='store_true')
     args = parser.parse_args()
     main(args.config, args.fromcsvfile)