diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 51 |
1 files changed, 5 insertions, 46 deletions
diff --git a/src/main.rs b/src/main.rs index e76da66..ea89b02 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,5 +1,4 @@ | |||
1 | extern crate regex; | 1 | extern crate regex; |
2 | use regex::Regex; | ||
3 | extern crate yaml_rust; | 2 | extern crate yaml_rust; |
4 | 3 | ||
5 | extern crate walkdir; | 4 | extern crate walkdir; |
@@ -9,26 +8,21 @@ use std::io::prelude::*; | |||
9 | use std::fs::File; | 8 | use std::fs::File; |
10 | use std::env; | 9 | use std::env; |
11 | use std::path::Path; | 10 | use std::path::Path; |
12 | use std::collections::HashMap; | ||
13 | 11 | ||
14 | mod pre_process; | 12 | mod pre_process; |
15 | mod section; | 13 | mod section; |
16 | use section::Section; | ||
17 | 14 | ||
18 | mod character; | 15 | mod character; |
19 | use character::{Images, Names, Traits, Character}; | 16 | use character::Character; |
20 | 17 | ||
21 | mod tags; | 18 | mod tags; |
22 | mod dl_list; | 19 | mod dl_list; |
23 | use dl_list::DLListItem; | 20 | mod tiles; |
24 | 21 | ||
25 | fn main() { | 22 | fn main() { |
26 | let raw_files = env::var("RAW_FILES").unwrap_or("characters".into()); | 23 | let raw_files = env::var("RAW_FILES").unwrap_or("characters".into()); |
27 | let base_path = Path::new(&raw_files); | 24 | let base_path = Path::new(&raw_files); |
28 | 25 | ||
29 | let re_extras = Regex::new(r#"(?is)Extra Details \| [0-9]+</H3>.*?<dl>(.*?)</dl>"#).unwrap(); | ||
30 | |||
31 | let mut sections: HashMap<String, Section> = character::get_sections(); | ||
32 | 26 | ||
33 | for entry in WalkDir::new(base_path).min_depth(1).into_iter().filter_map(|e| e.ok()) { | 27 | for entry in WalkDir::new(base_path).min_depth(1).into_iter().filter_map(|e| e.ok()) { |
34 | let mut f = File::open(entry.path()).expect("could not open file"); | 28 | let mut f = File::open(entry.path()).expect("could not open file"); |
@@ -40,43 +34,8 @@ fn main() { | |||
40 | 34 | ||
41 | let buf = pre_process::strip_irrelevant_content(&buf); | 35 | let buf = pre_process::strip_irrelevant_content(&buf); |
42 | 36 | ||
43 | section::process(&buf, &mut sections); | 37 | let mut char = Character::new(); |
44 | 38 | char.parse(&buf); | |
45 | // find optional extra details | 39 | println!("{:?}", char); |
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 | } | ||
51 | |||
52 | { | ||
53 | let name: &Section = §ions["name".into()]; | ||
54 | let image: &Section = §ions["image".into()]; | ||
55 | let misc: &Section = §ions["misc".into()]; | ||
56 | println!("{:?}", Character { | ||
57 | name: Names { | ||
58 | romaji: name.data["romaji".into()].clone(), | ||
59 | japanese: name.data["japanese".into()].clone(), | ||
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 | } | ||
64 | }, | ||
65 | image: Images { | ||
66 | thumb: image.data["thumb".into()].clone(), | ||
67 | full: image.data["full".into()].clone(), | ||
68 | }, | ||
69 | tags: tags::parse(&(§ions["tags".into()] as &Section).data["tags_raw".into()]), | ||
70 | traits: Traits { | ||
71 | official: dl_list::parse(&(§ions["traits"] as &Section).data["official_raw".into()]), | ||
72 | indexed: dl_list::parse(&(§ions["traits"] as &Section).data["indexed_raw".into()]), | ||
73 | }, | ||
74 | extra: extra_details, | ||
75 | role: match misc.data["role".into()].len() > 0 { | ||
76 | true => Some(misc.data["role".into()].clone()), | ||
77 | false => None | ||
78 | } | ||
79 | }); | ||
80 | } | ||
81 | } | 40 | } |
82 | } | 41 | } |