diff --git a/Cargo.lock b/Cargo.lock index 27df2ac..fb536ea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -724,7 +724,7 @@ dependencies = [ [[package]] name = "rss-anime-notifier-rs" -version = "0.2.1" +version = "0.2.2" dependencies = [ "chrono", "reqwest", diff --git a/Cargo.toml b/Cargo.toml index b726aab..85ec9f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rss-anime-notifier-rs" -version = "0.2.1" +version = "0.2.2" authors = ["blank X "] edition = "2018" diff --git a/src/main.rs b/src/main.rs index dac2421..e729a11 100644 --- a/src/main.rs +++ b/src/main.rs @@ -72,7 +72,22 @@ struct AiringSchedule { pub episode: i32 } -async fn async_main() { +async fn get_data(anime_id: i32) -> Root { + let client = Client::new(); + let json = json!({"query": QUERY, "variables": {"id": anime_id}}); + serde_json::from_str(&client.post("https://graphql.anilist.co/") + .header("Content-Type", "application/json") + .header("Accept", "application/json") + .body(json.to_string()) + .send() + .await + .unwrap() + .text() + .await + .unwrap()).unwrap() +} + +fn main() { let mut args = env::args(); let path = args.next().expect("Cannot get binary path"); let path = Path::new(&path).file_stem().unwrap().to_str().unwrap(); @@ -83,16 +98,11 @@ async fn async_main() { exit(1); } }; - let client = Client::new(); - let json = json!({"query": QUERY, "variables": {"id": anime_id}}); - let resp = client.post("https://graphql.anilist.co/") - .header("Content-Type", "application/json") - .header("Accept", "application/json") - .body(json.to_string()) - .send() - .await - .unwrap(); - let resp: Root = serde_json::from_str(&resp.text().await.unwrap()).unwrap(); + let resp = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .unwrap() + .block_on(get_data(anime_id)); let mut pub_date = Utc::now().to_rfc2822(); let mut last_build_date = pub_date.clone(); let resp = &resp.data.media; @@ -130,11 +140,3 @@ async fn async_main() { .unwrap(); println!("{}", channel.to_string()); } - -fn main() { - tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - .unwrap() - .block_on(async_main()); -}