Only use async for getting data from Anilist
This commit is contained in:
		
							parent
							
								
									adc02b3d03
								
							
						
					
					
						commit
						7732bce38b
					
				| 
						 | 
				
			
			@ -724,7 +724,7 @@ dependencies = [
 | 
			
		|||
 | 
			
		||||
[[package]]
 | 
			
		||||
name = "rss-anime-notifier-rs"
 | 
			
		||||
version = "0.2.1"
 | 
			
		||||
version = "0.2.2"
 | 
			
		||||
dependencies = [
 | 
			
		||||
 "chrono",
 | 
			
		||||
 "reqwest",
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
[package]
 | 
			
		||||
name = "rss-anime-notifier-rs"
 | 
			
		||||
version = "0.2.1"
 | 
			
		||||
version = "0.2.2"
 | 
			
		||||
authors = ["blank X <theblankx@protonmail.com>"]
 | 
			
		||||
edition = "2018"
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										40
									
								
								src/main.rs
								
								
								
								
							
							
						
						
									
										40
									
								
								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());
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue