Update tools/miradi.py
Browse files- tools/miradi.py +27 -0
tools/miradi.py
CHANGED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import urllib.parse
|
| 3 |
+
|
| 4 |
+
def duckduckgo_search(query):
|
| 5 |
+
""" Search DuckDuckGo using the instant answers API"""
|
| 6 |
+
|
| 7 |
+
try:
|
| 8 |
+
url = "https://api.duckduckgo.com/"
|
| 9 |
+
params = {"q": query, "format": "json", "no_redirect": 1, "no_html": 1}
|
| 10 |
+
response = requests.get(url, params=params, timeout=10)
|
| 11 |
+
response.raise_for_status()
|
| 12 |
+
data = response.json()
|
| 13 |
+
results = []
|
| 14 |
+
if data.get("AbstractText"):
|
| 15 |
+
results.append({
|
| 16 |
+
"title": data.get("Heading"),
|
| 17 |
+
"link": data.get("AbstractURL"),
|
| 18 |
+
"snippet": data.get("AbstracText")
|
| 19 |
+
})
|
| 20 |
+
|
| 21 |
+
for topic in data.get("RelatedTopics", []):
|
| 22 |
+
if "Text" in topic and "FirstURL" in topic:
|
| 23 |
+
result.append({
|
| 24 |
+
"title":
|
| 25 |
+
})
|
| 26 |
+
except error:
|
| 27 |
+
|