def updateMakeAndModel(): db=localDb.get_db() sql='select * from price_shenzhou' data=db.exec_sql(sql) for item in data: ob=item make,model=nameMapping.get(ob.get('name',''),(None,None)) if make: ob['make']=make if model: ob['model']=model db.insert('price_shenzhou',ob,False) db.commit() db.close()
def storeData(carPriceFilePath): result=[] failed=[] db=localDb.get_db() for line in open(carPriceFilePath): tmpLine=line.strip() ob=json.loads(tmpLine) # print ob result.append(ob) if len(result)==100: errorCode=db.insert_many('price_shenzhou',result) db.commit() if errorCode==-1: failed.extend(result) result=[] failed.extend(result) for item in failed: db.insert('price_shenzhou',item) db.commit() db.close()
def on_message(self, client, userdata, msg): Iot_Sensor = mydb.Sensor_Table(mydb.get_db()) now = datetime.datetime.now().replace(microsecond=0) msg.payload = msg.payload.decode("utf-8") dict = json.loads(msg.payload) iot_topic = "iot_" + dict["place"].replace("/", "_") + "_" print("Topic: " + msg.topic + '\nMessage: ' + msg.payload) for name in dict["value"].keys(): iot_name = iot_topic + name if Iot_Sensor.table_check(iot_name) == False: check_table = False print("{0} table does not exists".format(iot_name)) Iot_Sensor.table_create(iot_name) Iot_Sensor.inspectdb() Iot_Sensor.insert_data(iot_name, dict["value"][name]) print('{0} {1} {2}'.format(iot_name, str(dict["value"][name]), now))
def get_data_from_db(sql): db = mydb.get_db(conv=True) comments_data = list(db.exec_sql(sql)) comments_df = DataFrame(comments_data) return comments_df