def import_table(root, file_name, temp_file, cur, conn): print("%s/%s" % (root, file_name)) table_name = file_name[:-4] if "flightstats_" in file_name: table_name = table_name[12:] f = open(os.path.join(root, file_name)) header = f.readline() i = 0 while True: next_lines = list(islice(f, line_buffer_size)) if not next_lines: break write_temp_file(temp_file, header, next_lines) i += 1 ingest_command = csv_to_postgres.make_postgres_ingest_with_defaults( temp_file, table_name, cur) if i == 1: print(ingest_command) print("%s: %d lines processed" % (table_name, (i - 1) * line_buffer_size + len(next_lines))) cur.execute(ingest_command) conn.commit()
def import_table(root, file_name, temp_file, cur, conn): print("%s/%s" % (root, file_name)) create_temp_file(root, file_name, temp_file) table_name = file_name[:-4] ingest_command = csv_to_postgres.make_postgres_ingest_with_defaults(temp_file, table_name, cur) print(ingest_command) cur.execute(ingest_command) conn.commit()
def import_table(root, file_name, temp_file, cur, conn): print("%s/%s" % (root, file_name)) table_name = file_name[:-4] if "flightstats_" in file_name: table_name = table_name[12:] f = open(os.path.join(root, file_name)) header = f.readline() i = 0 while True: next_lines = list(islice(f, line_buffer_size)) if not next_lines: break write_temp_file(temp_file, header, next_lines) i += 1 ingest_command = csv_to_postgres.make_postgres_ingest_with_defaults(temp_file, table_name, cur) if i==1: print(ingest_command) print("%s: %d lines processed" % (table_name, (i-1)*line_buffer_size+len(next_lines))) cur.execute(ingest_command) conn.commit()