Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -85,9 +85,21 @@ def extract_text_from_webpage(html):
|
|
85 |
return text
|
86 |
|
87 |
# Function to perform a Google search and retrieve results
|
88 |
-
def google_search(term, num_results=5, lang="en", timeout=5, safe="active", ssl_verify=None, instructions=""):
|
89 |
print(f"Searching for term: {term}")
|
90 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
91 |
start = 0
|
92 |
all_results = []
|
93 |
|
@@ -106,7 +118,7 @@ def google_search(term, num_results=5, lang="en", timeout=5, safe="active", ssl_
|
|
106 |
url="https://www.google.com/search",
|
107 |
headers=headers,
|
108 |
params={
|
109 |
-
"q":
|
110 |
"num": num_results - start,
|
111 |
"hl": lang,
|
112 |
"start": start,
|
@@ -507,7 +519,10 @@ def scrape_and_display(query, num_results, instructions, web_search=True, use_ne
|
|
507 |
if use_news:
|
508 |
search_results = google_news_search(query, num_results)
|
509 |
else:
|
510 |
-
|
|
|
|
|
|
|
511 |
|
512 |
# Summarize each result
|
513 |
summarized_results = []
|
|
|
85 |
return text
|
86 |
|
87 |
# Function to perform a Google search and retrieve results
|
88 |
+
def google_search(term, num_results=5, lang="en", timeout=5, safe="active", ssl_verify=None, instructions="", days_back=365):
|
89 |
print(f"Searching for term: {term}")
|
90 |
+
|
91 |
+
# Calculate the date range
|
92 |
+
end_date = datetime.now()
|
93 |
+
start_date = end_date - timedelta(days=days_back)
|
94 |
+
|
95 |
+
# Format dates as strings
|
96 |
+
start_date_str = start_date.strftime("%Y-%m-%d")
|
97 |
+
end_date_str = end_date.strftime("%Y-%m-%d")
|
98 |
+
|
99 |
+
# Add the date range to the search term
|
100 |
+
search_term = f"{term} after:{start_date_str} before:{end_date_str}"
|
101 |
+
|
102 |
+
escaped_term = urllib.parse.quote_plus(search_term)
|
103 |
start = 0
|
104 |
all_results = []
|
105 |
|
|
|
118 |
url="https://www.google.com/search",
|
119 |
headers=headers,
|
120 |
params={
|
121 |
+
"q": search_term,
|
122 |
"num": num_results - start,
|
123 |
"hl": lang,
|
124 |
"start": start,
|
|
|
519 |
if use_news:
|
520 |
search_results = google_news_search(query, num_results)
|
521 |
else:
|
522 |
+
# Add the year-based search here
|
523 |
+
current_year = datetime.now().year
|
524 |
+
days_in_year = 365 if current_year % 4 != 0 else 366 # Account for leap years
|
525 |
+
search_results = google_search(query, num_results=num_results, instructions=instructions, days_back=days_in_year)
|
526 |
|
527 |
# Summarize each result
|
528 |
summarized_results = []
|