Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add random delay #13

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ rusqlite = { version = "0.30", features = ["bundled"] }
serde = { version = "1", features = ["derive"] }
threadpool = "1"
toml = "0.8"
rand = "0.8"

[dependencies.log4rs]
version = "1"
Expand Down
3 changes: 3 additions & 0 deletions config.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@ option = "--no-danmaku --proxy=no"
path = "bilibili/Gamker"
# 是否更新,设为 false 即不更新
update = true
# 是否需要一个随机的延迟,设为false即无延迟
delay = true

[[feed]]
url = "https://rsshub.app/bilibili/user/video/96639395"
interval = 60
option = "--no-danmaku --proxy=no"
path = "bilibili/Academia"
update = false
delay = true
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub struct Feed {
pub option: String,
pub path: String,
pub update: bool,
pub delay: bool,
}

impl Config {
Expand Down
10 changes: 10 additions & 0 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,20 @@ use crate::{
writer,
};

use std::time::Duration;
use rand::{thread_rng, Rng};

pub fn update(feed: &Feed) {
let connection = sqlite::open();

loop {
// 随机延迟0到600秒
let delay = &feed.delay;
if *delay == true {
let sleep_time = thread_rng().gen_range(0..600);
std::thread::sleep(Duration::from_secs(sleep_time));
}

let url = &feed.url;

let rss = Rss::new(url);
Expand Down