Main search function that handles search with retry mechanism. Args: query (str): Search query max_results (int): Maximum number of results to return max_retries (int): Maximum number of retry attempts
(query, max_results=10, max_retries=3)
| 47 | print(f"Snippet: {r.get('body', 'N/A')}") |
| 48 | |
| 49 | def search(query, max_results=10, max_retries=3): |
| 50 | """ |
| 51 | Main search function that handles search with retry mechanism. |
| 52 | |
| 53 | Args: |
| 54 | query (str): Search query |
| 55 | max_results (int): Maximum number of results to return |
| 56 | max_retries (int): Maximum number of retry attempts |
| 57 | """ |
| 58 | try: |
| 59 | results = search_with_retry(query, max_results, max_retries) |
| 60 | if results: |
| 61 | format_results(results) |
| 62 | |
| 63 | except Exception as e: |
| 64 | print(f"ERROR: Search failed: {str(e)}", file=sys.stderr) |
| 65 | sys.exit(1) |
| 66 | |
| 67 | def main(): |
| 68 | parser = argparse.ArgumentParser(description="Search using DuckDuckGo API") |