X-Git-Url: https://git.toastfreeware.priv.at/chrisu/seepark.git/blobdiff_plain/7bc31204e1355e06fc8be3c28563bb0c1c4441f7..3f3b346ada7cf690fb3f852aff925d740b288128:/seewasser.py?ds=inline diff --git a/seewasser.py b/seewasser.py index be5f149..922a990 100755 --- a/seewasser.py +++ b/seewasser.py @@ -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 @@ -79,6 +81,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() @@ -107,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__': @@ -115,6 +120,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)