wowie it exists
This commit is contained in:
commit
aa3d44de28
4 changed files with 1870 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/target
|
1801
Cargo.lock
generated
Normal file
1801
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load diff
12
Cargo.toml
Normal file
12
Cargo.toml
Normal file
|
@ -0,0 +1,12 @@
|
|||
[package]
|
||||
name = "anilist-data"
|
||||
version = "0.1.0"
|
||||
edition = "2024"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1.0"
|
||||
clap = { version = "4.5", features = ["derive"] }
|
||||
indicatif = "0.18.0"
|
||||
reqwest = { version = "0.12", features = ["blocking"] }
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
56
src/main.rs
Normal file
56
src/main.rs
Normal file
|
@ -0,0 +1,56 @@
|
|||
use std::{collections::HashMap, thread::sleep, time::Duration};
|
||||
|
||||
use anyhow::Result;
|
||||
use indicatif::ProgressIterator;
|
||||
use reqwest::header;
|
||||
use serde_json::Value;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let mut values: HashMap<u64, u64> = HashMap::new();
|
||||
let mut anime_count: u64 = 0;
|
||||
|
||||
for x in (0..100).progress() {
|
||||
let res = fetch_page(x)?;
|
||||
|
||||
let v: Value = serde_json::from_str(&res)?;
|
||||
|
||||
for y in 0..50 {
|
||||
let eps = v["data"]["Page"]["media"][y]["episodes"].as_u64();
|
||||
if eps.is_some() {
|
||||
if values.contains_key(&eps.unwrap()) {
|
||||
let cur = values.get(&eps.unwrap()).unwrap().clone();
|
||||
|
||||
values.insert(eps.unwrap(), cur + 1);
|
||||
} else {
|
||||
values.insert(eps.unwrap(), 1);
|
||||
};
|
||||
|
||||
anime_count = anime_count + 1;
|
||||
}
|
||||
}
|
||||
|
||||
sleep(Duration::from_secs(2));
|
||||
}
|
||||
println!("from {:#?} total anime", anime_count);
|
||||
|
||||
println!("{:#?}", values);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn fetch_page(page: u8) -> Result<String> {
|
||||
let mut headers = header::HeaderMap::new();
|
||||
headers.insert("content-type", "application/json".parse().unwrap());
|
||||
|
||||
let client = reqwest::blocking::Client::builder()
|
||||
.redirect(reqwest::redirect::Policy::none())
|
||||
.build()
|
||||
.unwrap();
|
||||
let res = client.post("https://graphql.anilist.co")
|
||||
.headers(headers)
|
||||
.body("{\"query\":\"query Query($page: Int, $perPage: Int, $sort: [MediaSort], $type: MediaType, $format: MediaFormat) {\\n Page(page: $page, perPage: $perPage) {\\n media(sort: $sort, type: $type, format: $format) {\\n episodes\\n title {\\n english\\n romaji\\n }\\n }\\n }\\n}\",\"variables\":{\"page\":".to_owned() + &page.to_string() + ",\"perPage\":50,\"sort\":\"POPULARITY_DESC\",\"type\":\"ANIME\",\"format\":\"TV\"}}")
|
||||
.send()?
|
||||
.text()?;
|
||||
|
||||
Ok(res)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue