aboutsummaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs20
1 files changed, 14 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index 7481376..f15a3dd 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,9 +1,9 @@
1#![feature(proc_macro)] 1#![feature(proc_macro)]
2#[macro_use] extern crate serde_derive; 2#[macro_use]
3extern crate serde_derive;
3extern crate serde_json; 4extern crate serde_json;
4 5
5extern crate regex; 6extern crate regex;
6extern crate yaml_rust;
7 7
8extern crate walkdir; 8extern crate walkdir;
9use walkdir::{WalkDir, DirEntry}; 9use walkdir::{WalkDir, DirEntry};
@@ -38,8 +38,12 @@ fn main() {
38 38
39 let active_threads = Arc::new(AtomicUsize::new(0)); 39 let active_threads = Arc::new(AtomicUsize::new(0));
40 40
41 41
42 let files: Arc<Mutex<Vec<DirEntry>>> = Arc::new(Mutex::new(WalkDir::new(base_path).min_depth(1).into_iter().filter_map(|e| e.ok()).collect())); 42 let files: Arc<Mutex<Vec<DirEntry>>> = Arc::new(Mutex::new(WalkDir::new(base_path)
43 .min_depth(1)
44 .into_iter()
45 .filter_map(|e| e.ok())
46 .collect()));
43 47
44 for i in 0..MAX_THREADS { 48 for i in 0..MAX_THREADS {
45 let files = files.clone(); 49 let files = files.clone();
@@ -58,7 +62,7 @@ fn main() {
58 } 62 }
59 } 63 }
60 let entry = entry.unwrap(); 64 let entry = entry.unwrap();
61 65
62 let mut f = File::open(entry.path()).expect("could not open file"); 66 let mut f = File::open(entry.path()).expect("could not open file");
63 let mut buf = String::new(); 67 let mut buf = String::new();
64 if let Err(_) = f.read_to_string(&mut buf) { 68 if let Err(_) = f.read_to_string(&mut buf) {
@@ -68,12 +72,16 @@ fn main() {
68 72
69 let buf = pre_process::strip_irrelevant_content(&buf); 73 let buf = pre_process::strip_irrelevant_content(&buf);
70 74
75 println!("{:?}", entry.path());
71 let mut char = Series::new(); 76 let mut char = Series::new();
72 char.parse(&buf); 77 char.parse(&buf);
73 78
74 let json = serde_json::to_string(&char).unwrap(); 79 let json = serde_json::to_string(&char).unwrap();
75 80
76 let out_file = out_path.join(entry.file_name().to_str().unwrap().replace("html", "json")); 81 let out_file = out_path.join(entry.file_name()
82 .to_str()
83 .unwrap()
84 .replace("html", "json"));
77 let mut o = File::create(&out_file).unwrap(); 85 let mut o = File::create(&out_file).unwrap();
78 o.write_all(json.as_bytes()).unwrap(); 86 o.write_all(json.as_bytes()).unwrap();
79 println!("{:?}", out_file); 87 println!("{:?}", out_file);