aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs36
1 files changed, 22 insertions, 14 deletions
diff --git a/src/main.rs b/src/main.rs
index ee8c3eb..e76da66 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,5 @@
1extern crate regex; 1extern crate regex;
2use regex::Regex;
2extern crate yaml_rust; 3extern crate yaml_rust;
3 4
4extern crate walkdir; 5extern crate walkdir;
@@ -11,27 +12,23 @@ use std::path::Path;
11use std::collections::HashMap; 12use std::collections::HashMap;
12 13
13mod pre_process; 14mod pre_process;
14use pre_process::Section; 15mod section;
15 16use section::Section;
16mod config;
17use config::Config;
18 17
19mod character; 18mod character;
20use character::{Images, Names, Traits, Character}; 19use character::{Images, Names, Traits, Character};
21 20
22mod tags; 21mod tags;
23mod traits; 22mod dl_list;
23use dl_list::DLListItem;
24 24
25fn main() { 25fn main() {
26 let raw_files = env::var("RAW_FILES").unwrap_or("characters".into()); 26 let raw_files = env::var("RAW_FILES").unwrap_or("characters".into());
27 let base_path = Path::new(&raw_files); 27 let base_path = Path::new(&raw_files);
28 28
29 let cfg = Config::from_file("config.yml", vec!["name", "image", "misc", "tags", "traits"]); 29 let re_extras = Regex::new(r#"(?is)Extra Details \| [0-9]+</H3>.*?<dl>(.*?)</dl>"#).unwrap();
30 30
31 let mut sections: HashMap<String, Section> = HashMap::new(); 31 let mut sections: HashMap<String, Section> = character::get_sections();
32 for (name, sec) in &cfg.sections {
33 sections.insert(name.clone(), Section::new(&name, &sec.pattern, sec.groups.clone()));
34 }
35 32
36 for entry in WalkDir::new(base_path).min_depth(1).into_iter().filter_map(|e| e.ok()) { 33 for entry in WalkDir::new(base_path).min_depth(1).into_iter().filter_map(|e| e.ok()) {
37 let mut f = File::open(entry.path()).expect("could not open file"); 34 let mut f = File::open(entry.path()).expect("could not open file");
@@ -43,7 +40,14 @@ fn main() {
43 40
44 let buf = pre_process::strip_irrelevant_content(&buf); 41 let buf = pre_process::strip_irrelevant_content(&buf);
45 42
46 pre_process::split_sections(&buf, &mut sections); 43 section::process(&buf, &mut sections);
44
45 // find optional extra details
46 let mut extra_details: Vec<DLListItem> = vec![];
47 let caps = re_extras.captures(&buf);
48 if caps.is_some() {
49 extra_details = dl_list::parse(caps.unwrap().at(1).unwrap());
50 }
47 51
48 { 52 {
49 let name: &Section = &sections["name".into()]; 53 let name: &Section = &sections["name".into()];
@@ -53,7 +57,10 @@ fn main() {
53 name: Names { 57 name: Names {
54 romaji: name.data["romaji".into()].clone(), 58 romaji: name.data["romaji".into()].clone(),
55 japanese: name.data["japanese".into()].clone(), 59 japanese: name.data["japanese".into()].clone(),
56 aliases: name.data["aliases".into()].split(", ").map(|s| s.to_string()).collect(), 60 aliases: match name.data["aliases".into()].len() > 0 {
61 true => name.data["aliases".into()].split(", ").map(|s| s.to_string()).collect(),
62 false => vec![]
63 }
57 }, 64 },
58 image: Images { 65 image: Images {
59 thumb: image.data["thumb".into()].clone(), 66 thumb: image.data["thumb".into()].clone(),
@@ -61,9 +68,10 @@ fn main() {
61 }, 68 },
62 tags: tags::parse(&(&sections["tags".into()] as &Section).data["tags_raw".into()]), 69 tags: tags::parse(&(&sections["tags".into()] as &Section).data["tags_raw".into()]),
63 traits: Traits { 70 traits: Traits {
64 official: traits::parse(&(&sections["traits"] as &Section).data["official_raw".into()]), 71 official: dl_list::parse(&(&sections["traits"] as &Section).data["official_raw".into()]),
65 indexed: traits::parse(&(&sections["traits"] as &Section).data["indexed_raw".into()]), 72 indexed: dl_list::parse(&(&sections["traits"] as &Section).data["indexed_raw".into()]),
66 }, 73 },
74 extra: extra_details,
67 role: match misc.data["role".into()].len() > 0 { 75 role: match misc.data["role".into()].len() > 0 {
68 true => Some(misc.data["role".into()].clone()), 76 true => Some(misc.data["role".into()].clone()),
69 false => None 77 false => None