Store original and cleaned files in batch folder
- Save original .txt file in the batch folder - Save cleaned .csv file with just batch number as filename (no '-cleaned' suffix) - Both files stored alongside the HTML and PDF outputs
This commit is contained in:
27
src/main.rs
27
src/main.rs
@@ -239,19 +239,28 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
|
|
||||||
println!("Konverterar {} till rensat format...", filename);
|
println!("Konverterar {} till rensat format...", filename);
|
||||||
|
|
||||||
let cleaned_path =
|
let temp_cleaned_path =
|
||||||
base_output_dir.join(format!("{}.cleaned.csv", filename.trim_end_matches(".txt")));
|
base_output_dir.join(format!("{}.temp.csv", filename.trim_end_matches(".txt")));
|
||||||
let batch_number = clean_csv_file(input_path, &cleaned_path)?;
|
let batch_number = clean_csv_file(input_path, &temp_cleaned_path)?;
|
||||||
|
|
||||||
println!(
|
|
||||||
"Konverterade {} transaktioner",
|
|
||||||
fs::read_to_string(&cleaned_path)?.lines().count() - 1
|
|
||||||
);
|
|
||||||
|
|
||||||
let output_dir = base_output_dir.join(&batch_number);
|
let output_dir = base_output_dir.join(&batch_number);
|
||||||
fs::create_dir_all(&output_dir)?;
|
fs::create_dir_all(&output_dir)?;
|
||||||
|
|
||||||
let batch = read_csv_file(&cleaned_path)?;
|
fs::copy(input_path, output_dir.join(format!("{}.txt", batch_number)))?;
|
||||||
|
fs::rename(
|
||||||
|
&temp_cleaned_path,
|
||||||
|
output_dir.join(format!("{}.csv", batch_number)),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
println!(
|
||||||
|
"Konverterade {} transaktioner",
|
||||||
|
fs::read_to_string(output_dir.join(format!("{}.csv", batch_number)))?
|
||||||
|
.lines()
|
||||||
|
.count()
|
||||||
|
- 1
|
||||||
|
);
|
||||||
|
|
||||||
|
let batch = read_csv_file(&output_dir.join(format!("{}.csv", batch_number)))?;
|
||||||
println!("Laddade {} transaktioner", batch.transactions.len());
|
println!("Laddade {} transaktioner", batch.transactions.len());
|
||||||
|
|
||||||
let first_date = batch.transactions.first().map(|t| t.date).unwrap();
|
let first_date = batch.transactions.first().map(|t| t.date).unwrap();
|
||||||
|
|||||||
Reference in New Issue
Block a user