Skip to content

Commit

Permalink
feat: basic CSV file read
Browse files Browse the repository at this point in the history
  • Loading branch information
DewaldV committed Apr 22, 2024
1 parent 1a2f7c4 commit 9a7e136
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 9 deletions.
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ clap = { version = "4.5.3", features = ["derive", "env"] }
csv = "1.3.0"
# monzo-lib = "0.4.4"
monzo-lib = { git = "https://github.com/DewaldV/monzo-lib.git" }
serde = "1.0.198"
thiserror = "1.0.58"
# monzo-lib = { path = "../monzo-lib" }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
2 changes: 2 additions & 0 deletions examples/batch/batch.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
account,category,description,amount
Personal,eating_out,test-transaction,500
2 changes: 1 addition & 1 deletion src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use monzo::Client;

use crate::{currency, Result};

#[derive(PartialEq, clap::ValueEnum, Clone, Copy)]
#[derive(PartialEq, Debug, Clone, Copy, serde::Deserialize, clap::ValueEnum)]
pub enum AccountType {
Personal,
Joint,
Expand Down
19 changes: 15 additions & 4 deletions src/batch.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
use std::{fs::File, path::Path};
use std::path::Path;

use crate::error::Result;
use crate::{accounts, error::Result};

#[derive(Debug, serde::Deserialize)]
struct Row {
account: accounts::AccountType,
category: String,
description: String,
amount: u32,
}

pub async fn run(_token: String, file: String) -> Result<()> {
let path = Path::new(&file);
println!("batch file path: {}", path.display());

let _batch_file = File::open(&path)?;

let mut reader = csv::Reader::from_path(path)?;
for result in reader.deserialize() {
let row: Row = result?;
dbg!(row);
}
Ok(())
}
3 changes: 3 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ pub enum Error {

#[error("IO error: {0}")]
IO(#[from] std::io::Error),

#[error("CSV error: {0}")]
CSV(#[from] csv::Error),
}

0 comments on commit 9a7e136

Please sign in to comment.