diff --git a/Cargo.toml b/Cargo.toml index a14e91a..8104140 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,14 +1,14 @@ [package] name = "aw" -version = "0.0.4" +version = "0.0.5" edition = "2021" [dependencies] -clap = { version = "4.5.15", features = ["derive"] } -tokio = { version = "1.39.2", default-features = false, features = ["rt-multi-thread", "rt"] } +clap = { version = "4.5.16", features = ["derive"] } +tokio = { version = "1.39.3", default-features = false, features = ["rt"] } reqwest = { version = "0.12.5", default-features = false, features = ["http2", "json", "rustls-tls"] } -serde_json = { version = "1.0.120", default-features = false, features = ["alloc"] } -serde = { version = "1.0.204", features = ["derive"] } +serde_json = { version = "1.0.125", default-features = false, features = ["alloc"] } +serde = { version = "1.0.208", features = ["derive"] } ring = { version = "0.17.8", default-features = false} indicatif = "0.17.8" chrono = "0.4.38" diff --git a/src/cli.rs b/src/cli.rs index 97a7896..ad76b79 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -2,12 +2,18 @@ use clap::Parser; #[derive(Parser)] struct Cli { - n: usize, + value: Option, } + fn main() -> Result<(), Box> { let start_time = std::time::Instant::now(); let cli = Cli::parse(); - let _ = ld_::interface(cli.n); + + let _ = match cli.value { + Some(n) => ld_::interface(n), + None => ld_::get_pool(), + }; + println!("Processing time: {:?}", start_time.elapsed()); Ok(()) } diff --git a/src/client/process.rs b/src/client/process.rs index d5a230f..5b65f2d 100644 --- a/src/client/process.rs +++ b/src/client/process.rs @@ -104,6 +104,9 @@ pub async fn batch_seed(warp: Vec) -> Vec { let _pb = mp.add(ProgressBar::new(tasks.len() as u64)); _pb.set_style(seed_style.clone()); + if tasks.len()>100{ + tokio::time::sleep(RETRY_DELAY).await; + } for task in tasks { if let Ok(Ok(warp)) = task.await { warps.push(warp); @@ -151,6 +154,9 @@ pub async fn batch_update(warp: Vec) -> Vec { let _pb = mp.add(ProgressBar::new(tasks.len() as u64)); _pb.set_style(update_style.clone()); + if tasks.len()>100{ + tokio::time::sleep(RETRY_DELAY).await; + } for task in tasks { if let Ok(Ok(warp)) = task.await { warps.push(warp); @@ -198,6 +204,9 @@ pub async fn batch_delete(warp: Vec) -> Vec { let _pb = mp.add(ProgressBar::new(tasks.len() as u64)); _pb.set_style(delete_style.clone()); + if tasks.len()>100{ + tokio::time::sleep(RETRY_DELAY).await; + } for task in tasks { if let Ok(Ok(warp)) = task.await { warps.push(warp); @@ -210,6 +219,11 @@ pub async fn batch_delete(warp: Vec) -> Vec { } pub async fn batch_info(warp: Vec){ + let mp = MultiProgress::new(); + let info_style = ProgressStyle::with_template("[{elapsed_precise}] [{eta_precise}] {wide_bar:.green/red} {pos:>7}/{len:7}") + .unwrap() + .tick_chars("⠁⠂⠄⡀⢀⠠⠐⠈ "); + let mut tasks = Vec::new(); for _warp in warp{ @@ -219,43 +233,23 @@ pub async fn batch_info(warp: Vec){ tasks.push(task); } + let _pb = mp.add(ProgressBar::new(tasks.len() as u64)); + _pb.set_style(info_style.clone()); + + if tasks.len()>100{ + tokio::time::sleep(RETRY_DELAY).await; + } + for task in tasks { if let Ok(Ok(info)) = task.await { - println!("{:#?}", info); + let quota:usize = info.parse().expect("Failed to convert quota to usize"); + if quota == 24598562000000000{ + _pb.inc(1); + } + else { + print!("-{}-", quota); + } } } -} - - - - // let _pb = mp.add(ProgressBar::new(seed_tasks.len() as u64)); - // _pb.set_style(update_style.clone()); - // for task in seed_tasks { - // if let Ok(Ok(warp)) = task.await { - // seed_warps.push(warp); - // } - // _pb.inc(1); - // } - // _pb.finish(); - - // tokio::time::sleep(RETRY_DELAY).await; - // let mut warps = Vec::new(); - // let mut tasks = Vec::new(); - - // for sw in seed_warps{ - // let ss = sw.license(); - // let task = tokio::spawn(async move { - // sw.update_license(ss).await - // }); - // tasks.push(task); - // } - - // let _pb = mp.add(ProgressBar::new(tasks.len() as u64)); - // _pb.set_style(update_style.clone()); - // for task in tasks { - // if let Ok(Ok(warp)) = task.await { - // warps.push(warp); - // } - // _pb.inc(1); - // } - // _pb.finish(); \ No newline at end of file + _pb.finish(); +} \ No newline at end of file diff --git a/src/client/warp.rs b/src/client/warp.rs index 56ced83..9b30d20 100644 --- a/src/client/warp.rs +++ b/src/client/warp.rs @@ -129,12 +129,8 @@ impl WARP { return Err(format!("GET HTTP error: {}", response.text().await?).into()); } - // let json = response.json().await?; let json: serde_json::Value = response.json().await?; let info = json["quota"].to_string(); - // let caption = json["candidates"][0]["content"]["parts"][0]["text"] - // .as_str() - // .ok_or_else(|| format!("Failed to parse response: {}", response_text))?; Ok(info) } diff --git a/src/lib.rs b/src/lib.rs index c9e76fa..04c1004 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,8 @@ pub mod client; use client::process; +const SECRET: &str = "secret.txt"; + pub fn interface(num: usize) -> Result<(), Box> { let rt = tokio::runtime::Builder::new_current_thread() .enable_all() @@ -24,3 +26,12 @@ pub fn interface(num: usize) -> Result<(), Box> { Ok(()) } + +pub fn get_pool() -> Result<(), Box> { + let raw = std::fs::read_to_string(SECRET)?; + let secrete = raw.replace("\n", " "); + let pool = client::cipher::encode(&secrete); + + println!("{:?}", pool); + Ok(()) +}