aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2016-10-01 17:07:35 (UTC)
committerjan <jan@ruken.pw>2016-10-01 17:07:35 (UTC)
commit9138d3e359fcf7283b78f48c8d2d58a492814773 (patch)
tree3997199c187d64c662f69206e2b95da85536fe96 /src/main.rs
parentad63b49b94bf4b4596e6420e37d265a57b77d731 (diff)
assignments & chars mit aehnlichen traits
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs51
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 @@
1extern crate regex; 1extern crate regex;
2use regex::Regex;
3extern crate yaml_rust; 2extern crate yaml_rust;
4 3
5extern crate walkdir; 4extern crate walkdir;
@@ -9,26 +8,21 @@ use std::io::prelude::*;
9use std::fs::File; 8use std::fs::File;
10use std::env; 9use std::env;
11use std::path::Path; 10use std::path::Path;
12use std::collections::HashMap;
13 11
14mod pre_process; 12mod pre_process;
15mod section; 13mod section;
16use section::Section;
17 14
18mod character; 15mod character;
19use character::{Images, Names, Traits, Character}; 16use character::Character;
20 17
21mod tags; 18mod tags;
22mod dl_list; 19mod dl_list;
23use dl_list::DLListItem; 20mod tiles;
24 21
25fn main() { 22fn 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 = &sections["name".into()];
54 let image: &Section = &sections["image".into()];
55 let misc: &Section = &sections["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(&(&sections["tags".into()] as &Section).data["tags_raw".into()]),
70 traits: Traits {
71 official: dl_list::parse(&(&sections["traits"] as &Section).data["official_raw".into()]),
72 indexed: dl_list::parse(&(&sections["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}