sam
12/13/2022, 10:35 PMdf = pd.read_csv(latest_file).reindex()
##print(df)
#
#
def insert_row(host: str = '192.168.1.15', port: int = 9009):
table_name: str = str(uuid.uuid1())
watermark = 1024 # Flush if the internal buffer exceeds 1KiB
with Sender(host=host, port=port, auto_flush=watermark) as sender:
total_rows = 0
last_flush = time.monotonic()
print('Inserting row...')
for index, row in df.iterrows():
# Print the index and values of each row
#print(f"Row {index}: {row}")
print(row.to_dict())
sender.row(
'hist-ohlc-daily', ####TABLE NAME
columns=row.to_dict())
total_rows += 1
# If the internal buffer is empty, then auto-flush triggered.
if len(sender) == 0:
print('Auto-flush triggered.')
last_flush = time.monotonic()
# Flush at least once every five seconds.
if time.monotonic() - last_flush > 30:
print('Timer-flushing triggered.')
sender.flush()
last_flush = time.monotonic()
print(f"table: {table_name}, total rows sent: {total_rows}")
print("(wait commitLag for all rows to be available)")
print("bye!")
if __name__ == '__main__':
insert_row()
Nicolas Hourcard
12/14/2022, 11:08 AMBolek Ziobrowski
12/14/2022, 11:15 AMsam
12/15/2022, 7:02 AM