simple-api-duckduckgo/use_cases.py

22 lines
762 B
Python
Raw Normal View History

2024-02-08 12:52:28 +01:00
from typing import Union
def search_ddg(repo, query: str) -> Union[dict, list]:
"""Search DuckDuckGo for a query
Args:
repo (DuckDuckGoGateway): The DuckDuckGoGateway repository
query (str): The query to search for
Returns:
Union[dict, list]: A list of search results
Example:
[
{
"title": "DuckDuckGo — Privacy, simplified.",
"link": "https://duckduckgo.com/",
"body": "The Internet privacy company that empowers you to seamlessly take control of your personal information online, without any tradeoffs.",
"icon": "/assets/meta/DDG-icon_256x256.png",
},
...
]
"""
2024-02-08 12:52:28 +01:00
return repo.search(query)