Browse Source

Minor Updates

master
Sarah Jamie Lewis 1 month ago
parent
commit
800e486e5f
1 changed files with 30 additions and 5 deletions
  1. +30
    -5
      src/main.rs

+ 30
- 5
src/main.rs View File

@@ -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<Vec<Transaction>, Box<dyn Error>>{
// Build the CSV reader and iterate over each record.
@@ -14,8 +15,6 @@ fn parse_bisq_transactions(account:&String) -> Result<Vec<Transaction>, Box<dyn
let mut rdr = csv::Reader::from_reader(file);
let mut trade_transactions: Vec<Transaction>= vec!();
for result in rdr.records() {
// The iterator yields Result<StringRecord, Error>, 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<Vec<Transaction>, Box<dyn
}

if details.contains("Withdrawn from wallet") {
let mut transaction = Transaction::new(date_time, format!("Widthdrawal from Bisq Trading Wallet"));
let mut transaction = Transaction::new(date_time, format!("Withdrawal from Bisq Trading Wallet"));
transaction.add_input(Input{
source: String::from("Assets:Trading"),
amount: amount.abs(),
@@ -135,8 +134,6 @@ fn parse_bisq_trades(account:&String) -> Result<Vec<Transaction>, Box<dyn Error>
let mut rdr = csv::Reader::from_reader(file);
let mut trade_transactions: Vec<Transaction>= vec!();
for result in rdr.records() {
// The iterator yields Result<StringRecord, Error>, 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<Vec<Transaction>, Box<dyn Error>>{
return Ok(trade_transactions);
}

fn price_db(historical_price_file:&String) -> Result<HashMap<NaiveDateTime,f64>, Box<dyn Error>> {
// 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<NaiveDateTime,f64> = 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<String> = 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());


Loading…
Cancel
Save