Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -73,16 +73,17 @@ def format_results(results):
|
|
73 |
debug_info += f"Raw API Response:\n```json\n{json.dumps(results, indent=2)}\n```\n\n"
|
74 |
|
75 |
try:
|
76 |
-
if isinstance(results, dict) and "results" in results
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
for result in news_results:
|
81 |
-
time_str = result.get("time", "Unknown time")
|
82 |
-
is_recent = is_recent_news(time_str)
|
83 |
-
debug_info += f"Article: {result.get('title', 'No Title')}\nTime: {time_str}, Is Recent: {is_recent}\n\n"
|
84 |
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
86 |
### [{result.get('title', 'No Title')}]({result.get('url', '#')})
|
87 |
|
88 |
{result.get('snippet', 'No Snippet')}
|
@@ -92,8 +93,8 @@ def format_results(results):
|
|
92 |
---
|
93 |
|
94 |
"""
|
95 |
-
|
96 |
-
|
97 |
### [{result.get('title', 'No Title')}]({result.get('url', '#')})
|
98 |
|
99 |
{result.get('snippet', 'No Snippet')}
|
@@ -103,17 +104,21 @@ def format_results(results):
|
|
103 |
---
|
104 |
|
105 |
"""
|
106 |
-
|
107 |
-
|
108 |
-
|
|
|
|
|
|
|
|
|
109 |
else:
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
except Exception as e:
|
|
|
114 |
all_results += f"*Error processing results: {str(e)}*\n\n"
|
115 |
recent_results += f"*Error processing results: {str(e)}*\n\n"
|
116 |
-
debug_info += f"Exception occurred: {str(e)}\n"
|
117 |
|
118 |
return all_results, recent_results, debug_info
|
119 |
|
|
|
73 |
debug_info += f"Raw API Response:\n```json\n{json.dumps(results, indent=2)}\n```\n\n"
|
74 |
|
75 |
try:
|
76 |
+
if isinstance(results, dict) and "results" in results:
|
77 |
+
if "news" in results["results"]:
|
78 |
+
news_results = results["results"]["news"]
|
79 |
+
debug_info += f"Number of news results: {len(news_results)}\n\n"
|
|
|
|
|
|
|
|
|
80 |
|
81 |
+
for result in news_results:
|
82 |
+
time_str = result.get("time", "Unknown time")
|
83 |
+
is_recent = is_recent_news(time_str)
|
84 |
+
debug_info += f"Article: {result.get('title', 'No Title')}\nTime: {time_str}, Is Recent: {is_recent}\n\n"
|
85 |
+
|
86 |
+
all_results += f"""
|
87 |
### [{result.get('title', 'No Title')}]({result.get('url', '#')})
|
88 |
|
89 |
{result.get('snippet', 'No Snippet')}
|
|
|
93 |
---
|
94 |
|
95 |
"""
|
96 |
+
if is_recent:
|
97 |
+
recent_results += f"""
|
98 |
### [{result.get('title', 'No Title')}]({result.get('url', '#')})
|
99 |
|
100 |
{result.get('snippet', 'No Snippet')}
|
|
|
104 |
---
|
105 |
|
106 |
"""
|
107 |
+
|
108 |
+
if recent_results == "## Recent News Results (Within 1 Day)\n\n":
|
109 |
+
recent_results += "*No recent news results found within 1 day.*\n\n"
|
110 |
+
else:
|
111 |
+
debug_info += "No 'news' key found in results\n"
|
112 |
+
all_results += "*No news results found in the API response.*\n\n"
|
113 |
+
recent_results += "*No news results found in the API response.*\n\n"
|
114 |
else:
|
115 |
+
debug_info += "Invalid API response structure\n"
|
116 |
+
all_results += "*Invalid API response structure.*\n\n"
|
117 |
+
recent_results += "*Invalid API response structure.*\n\n"
|
118 |
except Exception as e:
|
119 |
+
debug_info += f"Exception occurred: {str(e)}\n"
|
120 |
all_results += f"*Error processing results: {str(e)}*\n\n"
|
121 |
recent_results += f"*Error processing results: {str(e)}*\n\n"
|
|
|
122 |
|
123 |
return all_results, recent_results, debug_info
|
124 |
|