simple_json/
simple_json.rs

1//! Similar to the simple example, except now it's JSON
2
3use rustnao::{Handler, HandlerBuilder};
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        // Specifying our key, test_mode set to 0, only want to see Pixiv and Sankaku using a mask, nothing excluded, no one specific source, and 999 results at most
14        let handle = HandlerBuilder::default()
15            .api_key(key)
16            .num_results(999)
17            .db_mask([Handler::PIXIV, Handler::SANKAKU_CHANNEL].to_vec())
18            .build();
19        let result = handle.get_sauce_as_pretty_json(file, None, None).unwrap();
20        println!("{}", result);
21    }
22}