broo
This commit is contained in:
@@ -17,20 +17,27 @@ fn main() {
|
|||||||
let mut connection = client.get_connection().unwrap();
|
let mut connection = client.get_connection().unwrap();
|
||||||
|
|
||||||
loop{
|
loop{
|
||||||
let query_url: String = format!("https://api.marketaux.com/v1/news/all/?api_token={}&countries={}&sentiment_gte={}&sentiment_lte={}&language={}&published_after={}&limit={}", NEWS_API_KEY.clone(), encode("us,ca").into_owned(),encode(0.25f32.to_string().as_str()).into_owned(), encode((-0.25f32).to_string().as_str()).into_owned(), "en",
|
let query_url_gte: String = format!("https://api.marketaux.com/v1/news/all/?api_token={}&countries={}&sentiment_gte={}&language={}&published_after={}&limit={}", NEWS_API_KEY.clone(), encode("us,ca").into_owned(),encode(0.25f32.to_string().as_str()).into_owned(), "en",
|
||||||
encode((Local::now() - Duration::from_secs(20*60)).format("%Y-%m-%dT%H:%M:%S").to_string().as_str()).into_owned(), 10);
|
encode((Local::now() - Duration::from_secs(20*60)).format("%Y-%m-%dT%H:%M:%S").to_string().as_str()).into_owned(), 10);
|
||||||
|
let query_url_lte: String = format!("https://api.marketaux.com/v1/news/all/?api_token={}&countries={}&sentiment_lte={}&language={}&published_after={}&limit={}", NEWS_API_KEY.clone(), encode("us,ca").into_owned(), encode((-0.25f32).to_string().as_str()).into_owned(), "en",
|
||||||
|
encode((Local::now() - Duration::from_secs(20*60)).format("%Y-%m-%dT%H:%M:%S").to_string().as_str()).into_owned(), 10);
|
||||||
|
info!(" Query url: {}", query_url_gte);
|
||||||
|
let response_batch_gte = reqwest::blocking::get(query_url_gte.as_str()).unwrap().text().unwrap();
|
||||||
|
debug!("Query has returned: {}", response_batch_gte);
|
||||||
|
info!(" Query url: {}", query_url_lte);
|
||||||
|
let response_batch_lte = reqwest::blocking::get(query_url_lte.as_str()).unwrap().text().unwrap();
|
||||||
|
debug!("Query has returned: {}", response_batch_lte);
|
||||||
|
|
||||||
info!(" Query url: {}", query_url);
|
let returned_gte: Value = serde_json::from_str(response_batch_gte.as_str()).unwrap();
|
||||||
let response_batch = reqwest::blocking::get(query_url.as_str()).unwrap().text().unwrap();
|
let returned_lte: Value = serde_json::from_str(response_batch_lte.as_str()).unwrap();
|
||||||
debug!("Query has returned: {}", response_batch);
|
|
||||||
let returned: Value = serde_json::from_str(response_batch.as_str()).unwrap();
|
|
||||||
let articles: Vec<Value> = returned.get("data").unwrap().as_array().unwrap().to_vec();
|
|
||||||
|
|
||||||
|
let mut articles: Vec<Value> = returned_gte.get("data").unwrap().as_array().unwrap().to_vec();
|
||||||
|
articles.append(&mut returned_lte.get("data").unwrap().as_array().unwrap().to_vec());
|
||||||
let bytes_to_publish: String = serde_json::to_string(&strip_and_construct(articles)).unwrap();
|
let bytes_to_publish: String = serde_json::to_string(&strip_and_construct(articles)).unwrap();
|
||||||
|
|
||||||
let _: () = connection.publish("notifications", bytes_to_publish).unwrap();
|
let _: () = connection.publish("notifications", bytes_to_publish).unwrap();
|
||||||
|
|
||||||
sleep(Duration::from_secs(60*20));
|
sleep(Duration::from_secs(60*30));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user