Guiyom commited on
Commit
eeab0b3
·
verified ·
1 Parent(s): 0ead65a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
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 serpapi import google_search
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 SerpAPI."""
37
  try:
38
- params = {
39
- "q": query,
40
- "num": num_results,
41
- "api_key": self.serpapi_key,
42
- "engine": "google" # Specify the search engine
43
- }
44
-
45
- results = google_search(params) # Use the correct function
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 []