diff options
author | jan <jan@ruken.pw> | 2016-09-30 12:30:31 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2016-09-30 12:30:31 (UTC) |
commit | 361ea3a80a60bc6595a7a624b6cc5d71ddc8f6fc (patch) | |
tree | f25d133b1ff7cdac720af309144bf6b69eec801f /src/main.rs | |
parent | 4ff469246f420c5a91d2a25eab9c21421abd3de9 (diff) |
jetzt werden die Sektionen aus einer config.yml rausgezogen.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/src/main.rs b/src/main.rs index 97b3094..7d06fe7 100644 --- a/src/main.rs +++ b/src/main.rs | |||
@@ -1,4 +1,5 @@ | |||
1 | extern crate regex; | 1 | extern crate regex; |
2 | extern crate yaml_rust; | ||
2 | 3 | ||
3 | extern crate walkdir; | 4 | extern crate walkdir; |
4 | use walkdir::WalkDir; | 5 | use walkdir::WalkDir; |
@@ -12,13 +13,19 @@ use std::collections::HashMap; | |||
12 | mod pre_process; | 13 | mod pre_process; |
13 | use pre_process::Section; | 14 | use pre_process::Section; |
14 | 15 | ||
16 | mod config; | ||
17 | use config::Config; | ||
18 | |||
15 | fn main() { | 19 | fn main() { |
16 | let raw_files = env::var("RAW_FILES").unwrap_or("characters".into()); | 20 | let raw_files = env::var("RAW_FILES").unwrap_or("characters".into()); |
17 | let base_path = Path::new(&raw_files); | 21 | let base_path = Path::new(&raw_files); |
18 | 22 | ||
23 | let cfg = Config::from_file("config.yml"); | ||
24 | |||
19 | let mut sections: Vec<Section> = vec![]; | 25 | let mut sections: Vec<Section> = vec![]; |
20 | sections.push(Section::new("name", r#"(?is)Romaji Name.*?<TD>(.*?)\s?</TD>.*?Japanese Name.*?<TD>(.*?)\s?</TD>"#, vec!["romaji".into(), "japanese".into()])); | 26 | for (name, sec) in &cfg.sections { |
21 | sections.push(Section::new("image", r#"(?is)<H3 id="section99">.*<img src="(.*?)" alt=.*?></a><p><a href="(.*?)">View Full Size Image"#, vec!["thumb".into(), "full".into()])); | 27 | sections.push(Section::new(&name, &sec.pattern, sec.groups.clone())); |
28 | } | ||
22 | 29 | ||
23 | for entry in WalkDir::new(base_path).min_depth(1).into_iter().filter_map(|e| e.ok()) { | 30 | for entry in WalkDir::new(base_path).min_depth(1).into_iter().filter_map(|e| e.ok()) { |
24 | let mut f = File::open(entry.path()).expect("could not open file"); | 31 | let mut f = File::open(entry.path()).expect("could not open file"); |
@@ -32,11 +39,11 @@ fn main() { | |||
32 | 39 | ||
33 | pre_process::split_sections(&buf, &mut sections); | 40 | pre_process::split_sections(&buf, &mut sections); |
34 | 41 | ||
35 | let mut char: HashMap<String, HashMap<String, String>> = HashMap::new(); | 42 | let mut char: HashMap<String, HashMap<String, String>> = HashMap::new(); |
36 | for s in §ions { | 43 | for s in §ions { |
37 | char.insert(s.name.clone(), s.data.clone()); | 44 | char.insert(s.name.clone(), s.data.clone()); |
38 | } | 45 | } |
39 | 46 | ||
40 | println!("{:?}", char); | 47 | println!("{:?}", char); |
41 | } | 48 | } |
42 | } | 49 | } |