use tarzi::{
Format, Result, WebFetcher, config::Config, converter::Converter, search::SearchEngine,
};
#[tokio::main]
async fn main() -> Result<()> {
tracing_subscriber::fmt::init();
println!("=== Tarzi Simple Usage Example ===\n");
let mut config = Config::load().unwrap_or_default();
config.fetcher.web_driver = "chromedriver".to_string();
println!("1. Fetching content with HTTP mode:");
let mut fetcher = WebFetcher::from_config(&config);
let test_url = "https://httpbin.org/html";
match fetcher.fetch(test_url, Format::Html).await {
Ok(content) => println!(" HTTP request successful: {} characters", content.len()),
Err(e) => println!(" HTTP request failed: {e}"),
}
println!("\n2. Converting HTML to different formats:");
let html_content = r#"
<html>
<head><title>Test Page</title></head>
<body>
<h1>Welcome to Tarzi</h1>
<p>This is a <strong>test</strong> page with <a href="https://example.com">a link</a>.</p>
<ul>
<li>Item 1</li>
<li>Item 2</li>
</ul>
</body>
</html>
"#;
let converter = Converter::new();
match converter.convert(html_content, Format::Markdown).await {
Ok(markdown) => {
println!(" Markdown conversion:");
println!(" {}", markdown.trim());
}
Err(e) => println!(" Markdown conversion failed: {e}"),
}
match converter.convert(html_content, Format::Json).await {
Ok(json) => {
println!("\n JSON conversion:");
println!(" {}", json.trim());
}
Err(e) => println!(" JSON conversion failed: {e}"),
}
println!("\n3. Testing search engine configuration:");
println!(" Default search engine: {}", config.search.engine);
println!(
" Search browser fallback: {} (TARZI_SEARCH_BROWSER)",
config.search.browser
);
println!(" Search limit: {}", config.search.limit);
println!(" Query pattern: {}", config.search.query_pattern);
let search_engine = SearchEngine::from_config(&config);
println!(
" Search engine initialized (browser={}, engines={:?})",
search_engine.browser_enabled(),
search_engine.engines()
);
println!("\n=== Simple Example Complete ===");
Ok(())
}