From 33d1a608e6f2718b045d08fa530ba1790a21ff36 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Sun, 27 Jan 2019 17:41:59 +0400 Subject: Sun, 27 Jan 2019 17:41:59 +0400 Signed-off-by: Valentin Popov --- src/main.rs | 22 +++++++-------- src/parser.rs | 90 +++++++++++++++++++++++++++++------------------------------ 2 files changed, 56 insertions(+), 56 deletions(-) diff --git a/src/main.rs b/src/main.rs index 6135a15..dbf0f28 100644 --- a/src/main.rs +++ b/src/main.rs @@ -15,17 +15,17 @@ mod parser; use parser::*; fn main() { - let yaml = load_yaml!("cli/en.yml"); - let matches = App::from_yaml(yaml).get_matches(); + let yaml = load_yaml!("cli/en.yml"); + let matches = App::from_yaml(yaml).get_matches(); - let path = matches.value_of("FILE").unwrap(); + let path = matches.value_of("FILE").unwrap(); - match Path::new(path).exists() { - true => { - let file: File = File::open(path).unwrap(); - let data: ParserResult = parser(BufReader::new(file)); - println!("{}", serde_json::to_string_pretty(&data).unwrap()); - } - _ => panic!("File {:#?} does not exist or is not available.", path), - }; + match Path::new(path).exists() { + true => { + let file: File = File::open(path).unwrap(); + let data: ParserResult = parser(BufReader::new(file)); + println!("{}", serde_json::to_string_pretty(&data).unwrap()); + } + _ => panic!("File {:#?} does not exist or is not available.", path), + }; } diff --git a/src/parser.rs b/src/parser.rs index 2a2c2cf..20984c9 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -6,52 +6,52 @@ use xml::reader::{EventReader, XmlEvent}; #[derive(Serialize)] pub struct ParserResult { - pub external_id: String, - pub meeting_id: String, - pub meeting_name: String, - pub context: Value, + pub external_id: String, + pub meeting_id: String, + pub meeting_name: String, + pub context: Value, } pub fn parser(content: BufReader) -> ParserResult { - let mut data = ParserResult { - context: serde_json::from_str("{}").unwrap(), - external_id: "".to_string(), - meeting_id: "".to_string(), - meeting_name: "".to_string(), - }; - - for element in EventReader::new(content) { - match element { - Ok(XmlEvent::StartElement { - name, attributes, .. - }) => { - let el_name = name.local_name.to_string(); - - for attribute in attributes { - let attr_name: String = attribute.name.local_name.to_string(); - let attr_value: String = attribute.value.to_string(); - - if el_name == "meeting" && attr_name == "id" { - data.meeting_id = attr_value.clone(); - } - - if el_name == "meeting" && attr_name == "externalId" { - data.external_id = attr_value.clone(); - } - - if el_name == "meeting" && attr_name == "name" { - data.meeting_name = attr_value.clone(); - } - - if el_name == "metadata" && attr_name == "bn-recording-status" { - data.context = serde_json::from_str(&attr_value).unwrap(); - } - } - } - Err(error) => panic!(error), - _ => {} - } - } - - return data; + let mut data = ParserResult { + context: serde_json::from_str("{}").unwrap(), + external_id: "".to_string(), + meeting_id: "".to_string(), + meeting_name: "".to_string(), + }; + + for element in EventReader::new(content) { + match element { + Ok(XmlEvent::StartElement { + name, attributes, .. + }) => { + let el_name = name.local_name.to_string(); + + for attribute in attributes { + let attr_name: String = attribute.name.local_name.to_string(); + let attr_value: String = attribute.value.to_string(); + + if el_name == "meeting" && attr_name == "id" { + data.meeting_id = attr_value.clone(); + } + + if el_name == "meeting" && attr_name == "externalId" { + data.external_id = attr_value.clone(); + } + + if el_name == "meeting" && attr_name == "name" { + data.meeting_name = attr_value.clone(); + } + + if el_name == "metadata" && attr_name == "bn-recording-status" { + data.context = serde_json::from_str(&attr_value).unwrap(); + } + } + } + Err(error) => panic!(error), + _ => {} + } + } + + return data; } -- cgit v1.2.3