blob: 97b3094edbf4207c7852ae2edc4dea8cd968d209 (
plain)
| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
 | extern crate regex;
extern crate walkdir;
use walkdir::WalkDir;
use std::io::prelude::*;
use std::fs::File;
use std::env;
use std::path::Path;
use std::collections::HashMap;
mod pre_process;
use pre_process::Section;
fn main() {
    let raw_files = env::var("RAW_FILES").unwrap_or("characters".into());
    let base_path = Path::new(&raw_files);
    let mut sections: Vec<Section> = vec![];
	sections.push(Section::new("name", r#"(?is)Romaji Name.*?<TD>(.*?)\s?</TD>.*?Japanese Name.*?<TD>(.*?)\s?</TD>"#, vec!["romaji".into(), "japanese".into()]));
    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()]));
    for entry in WalkDir::new(base_path).min_depth(1).into_iter().filter_map(|e| e.ok()) {
        let mut f = File::open(entry.path()).expect("could not open file");
        let mut buf = String::new();
        if let Err(_) = f.read_to_string(&mut buf) {
            println!("invalid file: {}", entry.path().to_str().unwrap());
            continue;
        }
        let buf = pre_process::strip_irrelevant_content(&buf);
        pre_process::split_sections(&buf, &mut sections);
		let mut char: HashMap<String, HashMap<String, String>> = HashMap::new();
		for s in §ions {
			char.insert(s.name.clone(), s.data.clone());
		}
		println!("{:?}", char);
    }
}
 |