File size: 1,116 Bytes
b7b2b80
 
 
2586059
b7b2b80
79ce518
 
b7b2b80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
79ce518
 
 
 
b7b2b80
79ce518
b7b2b80
79ce518
 
 
b7b2b80
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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 []