Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -148,26 +148,25 @@ def get_today_matches() -> str:
|
|
| 148 |
def wiki_search(query: str) -> str:
|
| 149 |
"""
|
| 150 |
Fetches a short summary from Wikipedia for a given topic.
|
| 151 |
-
|
| 152 |
-
Args:
|
| 153 |
-
query: Topic to search on Wikipedia.
|
| 154 |
-
|
| 155 |
-
Returns:
|
| 156 |
-
A short summary of the topic.
|
| 157 |
"""
|
| 158 |
|
| 159 |
-
|
|
|
|
|
|
|
| 160 |
|
| 161 |
try:
|
| 162 |
response = requests.get(url, timeout=10)
|
| 163 |
|
| 164 |
if response.status_code != 200:
|
| 165 |
-
return "No Wikipedia page found
|
| 166 |
|
| 167 |
data = response.json()
|
| 168 |
|
| 169 |
-
|
| 170 |
-
|
|
|
|
|
|
|
|
|
|
| 171 |
except Exception as e:
|
| 172 |
return f"Error fetching Wikipedia data: {str(e)}"
|
| 173 |
|
|
|
|
| 148 |
def wiki_search(query: str) -> str:
|
| 149 |
"""
|
| 150 |
Fetches a short summary from Wikipedia for a given topic.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 151 |
"""
|
| 152 |
|
| 153 |
+
encoded_query = urllib.parse.quote(query)
|
| 154 |
+
|
| 155 |
+
url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{encoded_query}"
|
| 156 |
|
| 157 |
try:
|
| 158 |
response = requests.get(url, timeout=10)
|
| 159 |
|
| 160 |
if response.status_code != 200:
|
| 161 |
+
return "No Wikipedia page found."
|
| 162 |
|
| 163 |
data = response.json()
|
| 164 |
|
| 165 |
+
return {
|
| 166 |
+
"title": data.get("title"),
|
| 167 |
+
"summary": data.get("extract"),
|
| 168 |
+
"url": data.get("content_urls", {}).get("desktop", {}).get("page"),
|
| 169 |
+
}
|
| 170 |
except Exception as e:
|
| 171 |
return f"Error fetching Wikipedia data: {str(e)}"
|
| 172 |
|