srkdev384 commited on
Commit
11399c1
·
verified ·
1 Parent(s): c6dfefe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -10
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
- url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{query}"
 
 
160
 
161
  try:
162
  response = requests.get(url, timeout=10)
163
 
164
  if response.status_code != 200:
165
- return "No Wikipedia page found for this topic."
166
 
167
  data = response.json()
168
 
169
- return data.get("extract", "No summary available.")
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