Initialize CSV output file with header
(file_path: &str)
| 63 | |
| 64 | // Initialize CSV output file with header |
| 65 | pub async fn initialize_csv_output(file_path: &str) -> Result<(), Error> { |
| 66 | let file = File::create(file_path).await?; |
| 67 | let mut writer = BufWriter::new(file); |
| 68 | |
| 69 | // Create a CSV writer |
| 70 | let mut csv_writer = csv::WriterBuilder::new() |
| 71 | .from_writer(vec![]); |
| 72 | |
| 73 | // Write header using the CsvHit struct field names |
| 74 | csv_writer.write_record(&["identifier", "phone", "firstname", "lastname"])?; |
| 75 | |
| 76 | // Get the CSV content as bytes |
| 77 | let csv_content = csv_writer.into_inner()?; |
| 78 | |
| 79 | // Write to file |
| 80 | writer.write_all(&csv_content).await?; |
| 81 | writer.flush().await?; |
| 82 | |
| 83 | Ok(()) |
| 84 | } |
| 85 | |
| 86 | // Append a hit to the CSV output file |
| 87 | pub async fn append_csv_hit(file_path: &str, hit: &CsvHit) -> Result<(), Error> { |