import csv
import os
import configparser
-from sqlalchemy import create_engine, exc
+from sqlalchemy import create_engine
import warnings
import MySQLdb.cursors
engine = create_engine('mysql+mysqldb://{}:{}@{}/{}'.format(user, pwd, host, db), echo=False)
conn = engine.connect()
with warnings.catch_warnings():
- # ignore _mysql_exceptions.IntegrityError: (1062, "Duplicate entry '0316a2193bff-2018-08-29 14:30:00' for key 'sensorid_timestamp'")
- # TODO: the following doesn't work
+ # ignore _mysql_exceptions.Warning: Duplicate entry '0316a2193bff-2018-08-29 14:30:00' for key 'sensorid_timestamp'
warnings.simplefilter("ignore", category=MySQLdb.cursors.Warning)
- # TODO: this does but …?!
- try:
- conn.execute("insert 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)
- except exc.IntegrityError as e:
- if "1062" in str(e):
- pass
- else:
- raise
+ 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()