Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,7 +7,7 @@ import logging
|
|
| 7 |
from typing import Dict, List
|
| 8 |
from datetime import datetime
|
| 9 |
from bs4 import BeautifulSoup
|
| 10 |
-
from
|
| 11 |
from newsapi import NewsApiClient
|
| 12 |
|
| 13 |
# Set up logging
|
|
@@ -33,21 +33,17 @@ class RaindropSearchBot:
|
|
| 33 |
self.newsapi = NewsApiClient(api_key=self.newsapi_key)
|
| 34 |
|
| 35 |
def get_google_results(self, query: str, num_results: int = 5) -> List[Dict]:
|
| 36 |
-
"""Get Google search results using
|
| 37 |
try:
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
if 'organic_results' in results:
|
| 48 |
-
return results['organic_results'][:num_results]
|
| 49 |
-
return []
|
| 50 |
-
|
| 51 |
except Exception as e:
|
| 52 |
logger.error(f"Google search error: {e}")
|
| 53 |
return []
|
|
|
|
| 7 |
from typing import Dict, List
|
| 8 |
from datetime import datetime
|
| 9 |
from bs4 import BeautifulSoup
|
| 10 |
+
from googlesearch import search
|
| 11 |
from newsapi import NewsApiClient
|
| 12 |
|
| 13 |
# Set up logging
|
|
|
|
| 33 |
self.newsapi = NewsApiClient(api_key=self.newsapi_key)
|
| 34 |
|
| 35 |
def get_google_results(self, query: str, num_results: int = 5) -> List[Dict]:
|
| 36 |
+
"""Get Google search results using googlesearch-python."""
|
| 37 |
try:
|
| 38 |
+
search_results = []
|
| 39 |
+
for result in search(query, num_results=num_results, advanced=True):
|
| 40 |
+
search_results.append({
|
| 41 |
+
'title': result.title,
|
| 42 |
+
'link': result.url,
|
| 43 |
+
'snippet': result.description
|
| 44 |
+
})
|
| 45 |
+
return search_results
|
| 46 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
except Exception as e:
|
| 48 |
logger.error(f"Google search error: {e}")
|
| 49 |
return []
|