56 lines
1.9 KiB
Rust
56 lines
1.9 KiB
Rust
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)
|
|
}
|