-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix example, stable build and documentation
- Loading branch information
Victor Benarbia
committed
Sep 18, 2022
1 parent
a1d7288
commit 92712c5
Showing
6 changed files
with
286 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// reference example google search | ||
use serpapi::serpapi::Client; | ||
use std::collections::HashMap; | ||
use std::env; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
// // read secret api key from environment variable | ||
// // To get the key simply copy/paste from https://serpapi.com/dashboard. | ||
// let api_key = match env::var_os("API_KEY") { | ||
// Some(v) => v.into_string().unwrap(), | ||
// None => panic!("$API_KEY is not set"), | ||
// }; | ||
|
||
// println!("let's search about coffee on google"); | ||
// let mut default = HashMap::new(); | ||
// default.insert("api_key".to_string(), api_key); | ||
// default.insert("engine".to_string(), "google".to_string()); | ||
// // initialize the search engine | ||
// let client = Client::new(default); | ||
|
||
// let mut parameter = HashMap::new(); | ||
// parameter.insert( | ||
// "location".to_string(), | ||
// "Austin, TX, Texas, United States".to_string(), | ||
// ); | ||
// parameter.insert("q".to_string(), "coffee".to_string()); | ||
// let mut html_parameter = HashMap::new(); | ||
// html_parameter.clone_from(¶meter); | ||
|
||
// // search returns a JSON as serde_json::Value which can be accessed like a HashMap. | ||
// println!("waiting..."); | ||
// let results = client.search(parameter).await?; | ||
// let organic_results = results["organic_results"].as_array().unwrap(); | ||
// println!("results received"); | ||
// println!("--- JSON ---"); | ||
// println!(" - number of organic results: {}", organic_results.len()); | ||
// println!( | ||
// " - organic_results first result description: {}", | ||
// results["organic_results"][0]["about_this_result"]["source"]["description"] | ||
// ); | ||
// let places = results["local_results"]["places"].as_array().unwrap(); | ||
// println!("number of local_results: {}", places.len()); | ||
// println!(" - local_results first address: {}", places[0]["address"]); | ||
|
||
// // search returns text | ||
// println!("--- HTML search ---"); | ||
// let raw = client.html(html_parameter).await?; | ||
// print!(" - raw HTML size {} bytes\n", raw.len()); | ||
// print!( | ||
// " - async search completed with {}\n", | ||
// results["search_parameters"]["engine"] | ||
// ); | ||
|
||
// // // edit the location in the search | ||
// // println!("--- JSON search with a different location ---"); | ||
// // parameter = HashMap::<String, String>::new(); | ||
// // parameter.insert("location".to_string(), "Destin, Florida, United States".to_string()); | ||
// // client = Client::google(parameter, api_key); | ||
// // let results = client.json().await?; | ||
// // println!(">> search_parameters: {}", results["search_parameters"]); | ||
// // let places = results["local_results"]["places"].as_array().unwrap(); | ||
// // println!("number of local_results: {}\n", places.len()); | ||
// // println!("local_results first address: {}\n", places[0]["address"]); | ||
|
||
print!("ok"); | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.