Permalink
Browse files

Ofx parse working

Lib, for parse the xml of the ofx, changed to xmltree-rs and used the Box
resource. #4
  • Loading branch information...
fernandobatels committed Nov 28, 2018
1 parent 3f813ac commit 97a1259430184c963aab0032cf914a520386fc1a
Showing with 11 additions and 9 deletions.
  1. +1 −1 Cargo.toml
  2. +5 −6 src/backend/ofx.rs
  3. +1 −1 src/main.rs
  4. +4 −1 src/ui/movimentations.rs
@@ -9,7 +9,7 @@ authors = ["Luis Fernando Batels <luisfbatels@gmail.com>"]

[dependencies]
json = "*"
dummy_xml = "*"
xmltree = "*"
uuid = { version = "0.7", features = ["v4"] }
prettytable-rs = "*"
chrono = "*"
@@ -8,15 +8,14 @@

use std::fs::File;
use std::io::prelude::*;
use dummy_xml::parser::*;
use xmltree::*;
use backend::storage::*;
use backend::accounts::*;

pub struct Ofx<'a> {
storage: &'a mut Storage,
account: &'a mut Account,
file_doc: Document<'a>,
file_path: String,
pub file_doc: Box<Element>,
}

impl<'a> Ofx<'a> {
@@ -41,15 +40,15 @@ impl<'a> Ofx<'a> {

let xml_split: Vec<&str> = file_content.split("<OFX>").collect();

let xml_str = format!("<OFX>{}", xml_split[1]);
let xml_str = format!("<?xml version=\"1.0\" encoding=\"UTF-8\"?><OFX>{}", xml_split[1]);

let xml = parse_string(&xml_str);
let xml = Element::parse(xml_str.as_bytes());

if xml.is_err() {
return Err("Invalid XML content in OFX file");
}

Ok(Ofx { storage: storage, account: account, file_path: file_path, file_doc: xml.unwrap() })
Ok(Ofx { storage: storage, account: account, file_doc: Box::new(xml.unwrap()) })
}

}
@@ -14,7 +14,7 @@ extern crate prettytable;
extern crate chrono;
extern crate csv;
extern crate assert_cmd;
extern crate dummy_xml;
extern crate xmltree;

mod ui;
mod backend;
@@ -461,9 +461,12 @@ impl Movimentations {
// Shell mode

let mut account = Account::get_account(&mut storage, params[0].to_owned()).unwrap();
let ofx = Ofx::new(&mut storage, &mut account, params[1].to_owned())

let mut ofx = Ofx::new(&mut storage, &mut account, params[1].to_owned())
.expect("Couldn't open the ofx file");

ofx.file_doc.get_mut_child("BANKMSGSRSV1").expect("Can't find name element");

} else {
// Help mode
println!("How to use: bmoney movimentations ofx [account id] /path/to/file.ofx");

0 comments on commit 97a1259

Please sign in to comment.