aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Popov <info@valentineus.link>2019-01-27 16:41:59 +0300
committerValentin Popov <info@valentineus.link>2019-01-27 16:41:59 +0300
commit33d1a608e6f2718b045d08fa530ba1790a21ff36 (patch)
treeb91679e2d7a8b158f04e96f920a0f98d10a4afcf
parenta0694a3418534cc6e74e7b269327893fda5b57e9 (diff)
downloadbbb2json-33d1a608e6f2718b045d08fa530ba1790a21ff36.tar.xz
bbb2json-33d1a608e6f2718b045d08fa530ba1790a21ff36.zip
Sun, 27 Jan 2019 17:41:59 +0400
Signed-off-by: Valentin Popov <info@valentineus.link>
-rw-r--r--src/main.rs22
-rw-r--r--src/parser.rs90
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<File>) -> 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;
}