diff options
author | jan <jan@ruken.pw> | 2016-09-29 11:23:10 (UTC) |
---|---|---|
committer | jan <jan@ruken.pw> | 2016-09-29 11:23:10 (UTC) |
commit | 4ff469246f420c5a91d2a25eab9c21421abd3de9 (patch) | |
tree | 3208a8454fadc713d17716a5f0bd3d654fbf9448 /src/main.rs | |
parent | 9e59cd7e6a21751420ccbb853ac883154c6e578e (diff) |
parsen in eine grosse HashMap, jetzt auch mit namen (bisher ohne alias)
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/src/main.rs b/src/main.rs index 2123c6b..97b3094 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 | 2 | ||
4 | extern crate walkdir; | 3 | extern crate walkdir; |
5 | use walkdir::WalkDir; | 4 | use walkdir::WalkDir; |
@@ -7,7 +6,8 @@ use walkdir::WalkDir; | |||
7 | use std::io::prelude::*; | 6 | use std::io::prelude::*; |
8 | use std::fs::File; | 7 | use std::fs::File; |
9 | use std::env; | 8 | use std::env; |
10 | use std::path::{Path, PathBuf}; | 9 | use std::path::Path; |
10 | use std::collections::HashMap; | ||
11 | 11 | ||
12 | mod pre_process; | 12 | mod pre_process; |
13 | use pre_process::Section; | 13 | use pre_process::Section; |
@@ -17,12 +17,13 @@ fn main() { | |||
17 | let base_path = Path::new(&raw_files); | 17 | let base_path = Path::new(&raw_files); |
18 | 18 | ||
19 | let mut sections: Vec<Section> = vec![]; | 19 | 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()])); | ||
20 | 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()])); | 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()])); |
21 | 22 | ||
22 | for entry in WalkDir::new(base_path).min_depth(1).into_iter().filter_map(|e| e.ok()) { | 23 | for entry in WalkDir::new(base_path).min_depth(1).into_iter().filter_map(|e| e.ok()) { |
23 | let mut f = File::open(entry.path()).expect("could not open file"); | 24 | let mut f = File::open(entry.path()).expect("could not open file"); |
24 | let mut buf = String::new(); | 25 | let mut buf = String::new(); |
25 | if let Err(e) = f.read_to_string(&mut buf) { | 26 | if let Err(_) = f.read_to_string(&mut buf) { |
26 | println!("invalid file: {}", entry.path().to_str().unwrap()); | 27 | println!("invalid file: {}", entry.path().to_str().unwrap()); |
27 | continue; | 28 | continue; |
28 | } | 29 | } |
@@ -31,6 +32,11 @@ fn main() { | |||
31 | 32 | ||
32 | pre_process::split_sections(&buf, &mut sections); | 33 | pre_process::split_sections(&buf, &mut sections); |
33 | 34 | ||
34 | println!("{:?}", sections[0].data); | 35 | let mut char: HashMap<String, HashMap<String, String>> = HashMap::new(); |
36 | for s in §ions { | ||
37 | char.insert(s.name.clone(), s.data.clone()); | ||
38 | } | ||
39 | |||
40 | println!("{:?}", char); | ||
35 | } | 41 | } |
36 | } | 42 | } |