python實現一個定時將數據插入influxdb數據庫?
class Buffer(object): MAXSIZE = 8192 def __init__(self, conn, sql): self.conn = conn self.sql = sql self.buffer = [] def append(self, data): self.buffer.append(data) if len(self.buffer) > self.MAXSIZE: self.flush() def flush(self): data, self.buffer = self.buffer, [] curr = self.conn.cursor() curr.executemany(self.sql, data) self.conn.commit() # here are your code for init database connect conn_src and conn_store...buff = Buffer(conn_store, "insert into sybase_user values (%s, %s)")sql_query = "select a.id, a.name from user_info a where a.id=%s"curr_src = conn_src.cursor()curr_src.execute(sql_query, '0001')for row in curr_src: buff.append(row)buff.flush()