diff --git a/src/main.rs b/src/main.rs index 6ec8520..122e8af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -7,6 +7,7 @@ pub mod account; pub mod transaction; use std::env; use std::borrow::Borrow; +use std::collections::HashMap; fn parse_bisq_transactions(account:&String) -> Result, Box>{ // Build the CSV reader and iterate over each record. @@ -14,8 +15,6 @@ fn parse_bisq_transactions(account:&String) -> Result, Box= vec!(); for result in rdr.records() { - // The iterator yields Result, so we check the - // error here.. let record = result?; let details = &record[1]; let date = &record[0]; @@ -87,7 +86,7 @@ fn parse_bisq_transactions(account:&String) -> Result, Box Result, Box let mut rdr = csv::Reader::from_reader(file); let mut trade_transactions: Vec= vec!(); for result in rdr.records() { - // The iterator yields Result, so we check the - // error here.. let record = result?; let id = &record[0]; let date = &record[1]; @@ -196,11 +193,39 @@ fn parse_donations(account:&String) -> Result, Box>{ return Ok(trade_transactions); } +fn price_db(historical_price_file:&String) -> Result, Box> { + // Build the CSV reader and iterate over each record. + let file = File::open(String::from(historical_price_file))?; + let mut rdr = csv::Reader::from_reader(file); + let mut pricedb: HashMap = HashMap::new(); + for result in rdr.records() { + let record = result?; + let date = &record[0]; + let date_time = NaiveDateTime::parse_from_str(date,"%Y-%m-%d %H:%M:%S UTC")?; + //println!("[{}] {}", date_time, &record[1]); + let value :f64 = record[1].parse().unwrap(); + pricedb.insert(date_time, value); + } + return Ok(pricedb) +} + + fn main() { let args: Vec = env::args().collect(); let mut ledger = account::Account::new(); + let zectocad = price_db(String::from("./zec-cad.csv").borrow()).unwrap(); + for (k,v) in &zectocad { + println!("P {} ZEC {} $", k, v); + } + + let btctocad = price_db(String::from("./btc-cad.csv").borrow()).unwrap(); + for (k,v) in &btctocad { + println!("P {} BTC {} $", k, v); + } + + let donations = parse_donations(args[1].borrow()).unwrap(); for transaction in donations.iter() { ledger.add_transaction(transaction.clone());