aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
blob: a7f1f9d7fa8a7ea3d1850c66fda1c75e71ffd384 (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
43
44
45
46
47
48
49
50
51
#![feature(rustc_macro)]
#[macro_use] extern crate serde_derive;
extern crate serde_json;

extern crate regex;
extern crate yaml_rust;

extern crate walkdir;
use walkdir::WalkDir;

use std::io::prelude::*;
use std::fs::File;
use std::env;
use std::path::Path;

mod pre_process;
mod section;

mod character;
use character::Character;

mod tags;
mod dl_list;
mod tiles;

fn main() {
    let raw_files = env::var("RAW_FILES").unwrap_or("characters".into());
    let out_files = env::var("OUT").unwrap_or("json".into());
    let base_path = Path::new(&raw_files);
    let out_path = Path::new(&out_files);


    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);

        let mut char = Character::new();
        char.parse(&buf);

        let json = serde_json::to_string(&char).unwrap();

        let mut o = File::create(out_path.join(entry.file_name())).unwrap();
        o.write_all(json.as_bytes()).unwrap();
    }
}