import requests import urllib.parse def miradi_search(location, description): """ Search DuckDuckGo using the instant answers API""" query = f"{description} in {location}" try: url = "https://api.duckduckgo.com/" params = {"q": query, "format": "json", "no_redirect": 1, "no_html": 1} response = requests.get(url, params=params, timeout=10) response.raise_for_status() data = response.json() results = [] if data.get("AbstractText"): results.append({ "title": data.get("Heading"), "link": data.get("AbstractURL"), "snippet": data.get("AbstracText") }) for topic in data.get("RelatedTopics", []): if "Text" in topic and "FirstURL" in topic: results.append({ "title": topic.get("Text"), "link": topic.get("FirstURL"), "snippet": topic.get("Text") }) return results except error: print(f"[DuckDuckGo Error] {e}") return []