#[cfg(feature = "std")]
fn main() -> Result<clientele::SysexitsError, Box<dyn std::error::Error>> {
use asimov_apify_module::{api::*, find_actor_for, jq};
use asimov_module::getenv;
use clientele::SysexitsError::*;
use std::io::stdout;
clientele::dotenv().ok();
let args = clientele::args_os()?;
#[cfg(feature = "tracing")]
tracing_subscriber::fmt()
.with_writer(std::io::stderr)
.with_max_level(tracing_subscriber::filter::LevelFilter::WARN)
.init();
let urls: Vec<String> = args
.iter()
.skip(1)
.map(|arg| arg.to_string_lossy().into())
.collect();
if urls.is_empty() {
return Ok(EX_OK);
}
let Some(api_key) = getenv::var_secret("APIFY_TOKEN") else {
return Ok(EX_CONFIG); };
let api = Apify::new(api_key)?;
for url in urls {
let Some(actor) = find_actor_for(&url) else {
return Ok(EX_UNAVAILABLE); };
let response = match actor.id {
"apify~google-search-scraper" => jq::google_search()
.filter_json_str(api.google_search(&url.parse().map_err(|_| EX_DATAERR)?)?)?,
"C2Wk3I6xAqC4Xi63f" => jq::x_follows()
.filter_json_str(api.x_follows(&url.parse().map_err(|_| EX_DATAERR)?)?)?,
"VhxlqQXRwhW8H5hNV" => jq::linkedin_profile()
.filter_json_str(api.linkedin_profile(&url.parse().map_err(|_| EX_DATAERR)?)?)?,
"dSCLg0C3YEZ83HzYX" => jq::instagram_profile()
.filter_json_str(api.instagram_profile(&url.parse().map_err(|_| EX_DATAERR)?)?)?,
_ => {
return Ok(EX_UNAVAILABLE); }
};
if cfg!(feature = "pretty") {
colored_json::write_colored_json(&response, &mut stdout())?;
println!();
} else {
println!("{}", serde_json::to_string(&response).unwrap());
}
}
Ok(EX_OK)
}
#[cfg(not(feature = "std"))]
fn main() {
unimplemented!("asimov-apify-importer requires the 'std' feature")
}