init
This commit is contained in:
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/target
|
||||
0
.gitlab-ci.yml
Normal file
0
.gitlab-ci.yml
Normal file
11
Cargo.toml
Normal file
11
Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "pbc"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
reqwest = {version = "0.11", features = ["blocking"]}
|
||||
scraper = "0.18.1"
|
||||
bytes = "1.5.0"
|
||||
4
Dockerfile
Normal file
4
Dockerfile
Normal file
@@ -0,0 +1,4 @@
|
||||
FROM ubuntu:latest
|
||||
LABEL authors="123ee"
|
||||
|
||||
ENTRYPOINT ["top", "-b"]
|
||||
16
src/file.rs
16
src/file.rs
@@ -1,6 +1,6 @@
|
||||
use std::fs;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
use std::io::{Read, Write};
|
||||
use std::path::Path;
|
||||
use bytes::Bytes;
|
||||
use bytes;
|
||||
@@ -16,3 +16,17 @@ pub(crate) fn write_file(path: &str, content: Bytes) -> Result<(), std::io::Erro
|
||||
file.write_all(&content)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn read_file(path: &str) -> Result<Bytes, std::io::Error> {
|
||||
let mut file = File::open(path)?;
|
||||
let mut contents = Vec::new();
|
||||
file.read_to_end(&mut contents)?;
|
||||
Ok(Bytes::from(contents))
|
||||
}
|
||||
|
||||
pub(crate) fn read_file_string(path: &str) -> Result<String, std::io::Error> {
|
||||
let mut file = File::open(path)?;
|
||||
let mut contents = String::new();
|
||||
file.read_to_string(&mut contents)?;
|
||||
Ok(contents)
|
||||
}
|
||||
17
src/main.rs
17
src/main.rs
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user