24 lines
492 B
Python
24 lines
492 B
Python
from ddgs import DDGS
|
|
import re
|
|
|
|
def perform_search(query: str) -> dict:
|
|
try:
|
|
results = DDGS().text(query, max_results=3)
|
|
return results
|
|
except Exception as e:
|
|
return {"error":str(e), "results":[]}
|
|
|
|
|
|
|
|
|
|
def parse_results(results: list[dict]) -> list[dict]:
|
|
return [
|
|
{
|
|
"url": r.get("href", ""), #
|
|
"snippet": r.get("body", "")[:500]
|
|
}
|
|
for r in results
|
|
if r.get("href", "").startswith('https://')
|
|
]
|
|
|
|
|