This commit is contained in:
lychang
2024-01-12 04:10:11 +08:00
parent eb2547e1c6
commit 86e60f1e5c
6 changed files with 43 additions and 6 deletions

View File

@@ -1,6 +1,9 @@
use std::io::Read;
use std::str::FromStr;
use std::thread;
use std::time::Duration;
use bytes::Bytes;
mod file;
@@ -9,18 +12,22 @@ mod web_parser;
fn main() {
let mut continue_flag = true;
let mut idx: i32 = 1;
let mut idx: i32;
let index = file::read_file_string("cache/index").expect("Read index error");
if index.is_empty() {
idx = 1;
} else {
idx = i32::from_str(&index).expect("Index Corrupted");
}
while continue_flag {
let name = web_parser::get_title(idx);
if name == "" {
continue_flag = false;
} else {
web_parser::download_images(idx, &name);
idx += 1;
}
thread::sleep(Duration::from_millis(300));
idx += 1;
if idx > 3 {
continue_flag = false;
}
}
file::write_file("cache/index", Bytes::from(idx.to_string())).expect(&format!("Write index error: {}", idx));
}