feat: scrape user regions
This commit is contained in:
1
sdgb-cli/src/cache/mod.rs
vendored
1
sdgb-cli/src/cache/mod.rs
vendored
@@ -14,6 +14,7 @@ static DATABASE: LazyLock<redb::Database> = LazyLock::new(|| {
|
||||
pub const PLAYERS: TableDefinition<'_, u32, Vec<u8>> = redb::TableDefinition::new("players");
|
||||
pub const PLAYER_B50: TableDefinition<'_, u32, Vec<u8>> = redb::TableDefinition::new("b50");
|
||||
pub const PLAYER_RECORD: TableDefinition<'_, u32, Vec<u8>> = redb::TableDefinition::new("records");
|
||||
pub const PLAYER_REGION: TableDefinition<'_, u32, Vec<u8>> = redb::TableDefinition::new("regions");
|
||||
|
||||
pub fn write_txn() -> Result<WriteTransaction, redb::Error> {
|
||||
Ok(DATABASE.begin_write()?)
|
||||
|
||||
@@ -95,6 +95,16 @@ pub enum Commands {
|
||||
max_rating: i64,
|
||||
},
|
||||
#[cfg(feature = "fetchall")]
|
||||
ScrapeAllRegion {
|
||||
#[arg(short, long, default_value_t = 5)]
|
||||
concurrency: usize,
|
||||
|
||||
#[arg(long, default_value_t = 1000)]
|
||||
min_rating: i64,
|
||||
#[arg(long, default_value_t = 16500)]
|
||||
max_rating: i64,
|
||||
},
|
||||
#[cfg(feature = "fetchall")]
|
||||
ScrapeAllRecord {
|
||||
#[arg(short, long, default_value_t = 5)]
|
||||
concurrency: usize,
|
||||
|
||||
@@ -284,6 +284,30 @@ async fn main() -> Result<(), Box<dyn snafu::Error>> {
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
#[cfg(feature = "fetchall")]
|
||||
Commands::ScrapeAllRegion {
|
||||
concurrency,
|
||||
min_rating,
|
||||
max_rating,
|
||||
} => {
|
||||
use sdgb_api::title::methods::GetUserRegionApiExt;
|
||||
|
||||
use crate::{
|
||||
cache::{PLAYER_REGION, PLAYERS},
|
||||
utils::helpers::{cached_concurrent_fetch, read_cache},
|
||||
};
|
||||
|
||||
let mut players: Vec<GetUserPreviewApiResp> = read_cache(PLAYERS)?;
|
||||
players.retain(|p| p.player_rating >= min_rating && p.player_rating <= max_rating);
|
||||
|
||||
cached_concurrent_fetch::<GetUserRegionApiExt>(
|
||||
players.iter().map(|p| p.user_id).collect::<Vec<u32>>(),
|
||||
&client,
|
||||
concurrency,
|
||||
PLAYER_REGION,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
||||
#[cfg(feature = "fetchall")]
|
||||
Commands::ListAllUserDump {} => {
|
||||
|
||||
Reference in New Issue
Block a user