diff options
author | jan <jan@ruken.pw> | 2016-10-01 10:45:55 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2016-10-01 10:45:55 (UTC) |
commit | ad63b49b94bf4b4596e6420e37d265a57b77d731 (patch) | |
tree | 73234b1a5f4d34e6b1771e4309374fd05bebd881 /src/main.rs | |
parent | a6b37fa5e1bd505adfae4888896be2a3aa49ec3a (diff) |
config entfernt, extra details parsen
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 36 |
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 @@ | |||
1 | extern crate regex; | 1 | extern crate regex; |
2 | use regex::Regex; | ||
2 | extern crate yaml_rust; | 3 | extern crate yaml_rust; |
3 | 4 | ||
4 | extern crate walkdir; | 5 | extern crate walkdir; |
@@ -11,27 +12,23 @@ use std::path::Path; | |||
11 | use std::collections::HashMap; | 12 | use std::collections::HashMap; |
12 | 13 | ||
13 | mod pre_process; | 14 | mod pre_process; |
14 | use pre_process::Section; | 15 | mod section; |
15 | 16 | use section::Section; | |
16 | mod config; | ||
17 | use config::Config; | ||
18 | 17 | ||
19 | mod character; | 18 | mod character; |
20 | use character::{Images, Names, Traits, Character}; | 19 | use character::{Images, Names, Traits, Character}; |
21 | 20 | ||
22 | mod tags; | 21 | mod tags; |
23 | mod traits; | 22 | mod dl_list; |
23 | use dl_list::DLListItem; | ||
24 | 24 | ||
25 | fn main() { | 25 | fn 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 = §ions["name".into()]; | 53 | let name: &Section = §ions["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(&(§ions["tags".into()] as &Section).data["tags_raw".into()]), | 69 | tags: tags::parse(&(§ions["tags".into()] as &Section).data["tags_raw".into()]), |
63 | traits: Traits { | 70 | traits: Traits { |
64 | official: traits::parse(&(§ions["traits"] as &Section).data["official_raw".into()]), | 71 | official: dl_list::parse(&(§ions["traits"] as &Section).data["official_raw".into()]), |
65 | indexed: traits::parse(&(§ions["traits"] as &Section).data["indexed_raw".into()]), | 72 | indexed: dl_list::parse(&(§ions["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 |