aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorjan <jan@ruken.pw>2016-09-30 12:30:31 (UTC)
committerjan <jan@ruken.pw>2016-09-30 12:30:31 (UTC)
commit361ea3a80a60bc6595a7a624b6cc5d71ddc8f6fc (patch)
treef25d133b1ff7cdac720af309144bf6b69eec801f /src/main.rs
parent4ff469246f420c5a91d2a25eab9c21421abd3de9 (diff)
jetzt werden die Sektionen aus einer config.yml rausgezogen.
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs21
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 @@
1extern crate regex; 1extern crate regex;
2extern crate yaml_rust;
2 3
3extern crate walkdir; 4extern crate walkdir;
4use walkdir::WalkDir; 5use walkdir::WalkDir;
@@ -12,13 +13,19 @@ use std::collections::HashMap;
12mod pre_process; 13mod pre_process;
13use pre_process::Section; 14use pre_process::Section;
14 15
16mod config;
17use config::Config;
18
15fn main() { 19fn 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 &sections { 43 for s in &sections {
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}