From b337375e389087a247e202d65e1c95fcc395ac63 Mon Sep 17 00:00:00 2001 From: Andros Fenollosa Date: Fri, 9 Feb 2024 08:39:07 +0100 Subject: [PATCH] Remove import and add more commentaries --- gateways/externals.py | 1 + main.py | 6 +++++- use_cases.py | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/gateways/externals.py b/gateways/externals.py index a612d03..e6f1ace 100644 --- a/gateways/externals.py +++ b/gateways/externals.py @@ -3,6 +3,7 @@ from bs4 import BeautifulSoup from typing import Union class DuckDuckGoGateway: + """Gateway to DuckDuckGo search engine""" url = "https://duckduckgo.com/html/" headers = { "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:84.0) Gecko/20100101 Firefox/84.0", diff --git a/main.py b/main.py index 80efae1..ba8122e 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,3 @@ -from typing import Union from fastapi import FastAPI from gateways.externals import DuckDuckGoGateway from use_cases import search_ddg @@ -7,5 +6,10 @@ app = FastAPI() @app.get("/search/") def api_search(q: str): + """Search for a query in DuckDuckGo. + Args: + q (str): The query to search for. + Returns: + dict: The search results.""" repo = DuckDuckGoGateway() return search_ddg(repo, q) diff --git a/use_cases.py b/use_cases.py index 810f3e2..eab3b06 100644 --- a/use_cases.py +++ b/use_cases.py @@ -1,4 +1,21 @@ 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", + }, + ... + ] + """ return repo.search(query)