filter/
filter.rs

1//! Now, we wish to filter out our results such that we have a minimum similarity and we reject any empty sources
2
3use rustnao::{HandlerBuilder, Sauce};
4
5fn main() {
6    let data = std::fs::read_to_string("config.json").expect("Couldn't read file.");
7    let json: serde_json::Value =
8        serde_json::from_str(data.as_str()).expect("JSON not well formatted.");
9    let api_key = json["api_key"].as_str();
10    let file = "https://i.imgur.com/W42kkKS.jpg";
11
12    if let Some(key) = api_key {
13        let handle = HandlerBuilder::default().api_key(key).build();
14        handle.set_min_similarity(61.31);
15        let result: Vec<Sauce> = handle
16            .get_sauce(file, None, None)
17            .unwrap()
18            .into_iter()
19            .filter(|sauce| !sauce.has_empty_url())
20            .collect(); // Remove empty results
21        for i in result {
22            println!("{:?}", i);
23        }
24    }
25}