extern crate regex; use regex::Regex; extern crate yaml_rust; extern crate walkdir; use walkdir::WalkDir; use std::io::prelude::*; use std::fs::File; use std::env; use std::path::Path; use std::collections::HashMap; mod pre_process; mod section; use section::Section; mod character; use character::{Images, Names, Traits, Character}; mod tags; mod dl_list; use dl_list::DLListItem; fn main() { let raw_files = env::var("RAW_FILES").unwrap_or("characters".into()); let base_path = Path::new(&raw_files); let re_extras = Regex::new(r#"(?is)Extra Details \| [0-9]+.*?
(.*?)
"#).unwrap(); let mut sections: HashMap = character::get_sections(); for entry in WalkDir::new(base_path).min_depth(1).into_iter().filter_map(|e| e.ok()) { let mut f = File::open(entry.path()).expect("could not open file"); let mut buf = String::new(); if let Err(_) = f.read_to_string(&mut buf) { println!("invalid file: {}", entry.path().to_str().unwrap()); continue; } let buf = pre_process::strip_irrelevant_content(&buf); section::process(&buf, &mut sections); // find optional extra details let mut extra_details: Vec = vec![]; let caps = re_extras.captures(&buf); if caps.is_some() { extra_details = dl_list::parse(caps.unwrap().at(1).unwrap()); } { let name: &Section = §ions["name".into()]; let image: &Section = §ions["image".into()]; let misc: &Section = §ions["misc".into()]; println!("{:?}", Character { name: Names { romaji: name.data["romaji".into()].clone(), japanese: name.data["japanese".into()].clone(), aliases: match name.data["aliases".into()].len() > 0 { true => name.data["aliases".into()].split(", ").map(|s| s.to_string()).collect(), false => vec![] } }, image: Images { thumb: image.data["thumb".into()].clone(), full: image.data["full".into()].clone(), }, tags: tags::parse(&(§ions["tags".into()] as &Section).data["tags_raw".into()]), traits: Traits { official: dl_list::parse(&(§ions["traits"] as &Section).data["official_raw".into()]), indexed: dl_list::parse(&(§ions["traits"] as &Section).data["indexed_raw".into()]), }, extra: extra_details, role: match misc.data["role".into()].len() > 0 { true => Some(misc.data["role".into()].clone()), false => None } }); } } }