Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -70,28 +70,38 @@ def format_results(results):
|
|
70 |
.news-title { font-size: 18px; color: #1a0dab; text-decoration: none; }
|
71 |
.news-snippet { color: #545454; margin: 10px 0; }
|
72 |
.news-meta { font-size: 12px; color: #006621; }
|
|
|
73 |
</style>
|
74 |
<div class="news-container">
|
75 |
<h2>Search Results (Last 24 Hours)</h2>
|
76 |
"""
|
77 |
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
if
|
83 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
else:
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
<a href="{result.get('url', '#')}" class="news-title">{result.get('title', 'No Title')}</a>
|
89 |
-
<p class="news-snippet">{result.get('snippet', 'No Snippet')}</p>
|
90 |
-
<p class="news-meta">Source: {result.get('channel', 'Unknown')} - {result.get('time', 'Unknown time')}</p>
|
91 |
-
</div>
|
92 |
-
"""
|
93 |
-
else:
|
94 |
-
html_output += "<p>Unexpected response format or no results found.</p>"
|
95 |
|
96 |
html_output += "</div>"
|
97 |
return html_output
|
|
|
70 |
.news-title { font-size: 18px; color: #1a0dab; text-decoration: none; }
|
71 |
.news-snippet { color: #545454; margin: 10px 0; }
|
72 |
.news-meta { font-size: 12px; color: #006621; }
|
73 |
+
.debug-info { background-color: #f0f0f0; padding: 10px; margin-top: 20px; border-radius: 5px; }
|
74 |
</style>
|
75 |
<div class="news-container">
|
76 |
<h2>Search Results (Last 24 Hours)</h2>
|
77 |
"""
|
78 |
|
79 |
+
# 디버깅 정보 추가
|
80 |
+
html_output += f'<div class="debug-info"><h3>Debug Info:</h3><pre>{json.dumps(results, indent=2)}</pre></div>'
|
81 |
+
|
82 |
+
try:
|
83 |
+
if isinstance(results, dict) and "results" in results:
|
84 |
+
news_results = results["results"].get("news", [])
|
85 |
+
if not news_results:
|
86 |
+
html_output += "<p>No news results found in the API response.</p>"
|
87 |
+
else:
|
88 |
+
filtered_results = [result for result in news_results if is_within_24_hours(result.get("time", "").strip())]
|
89 |
+
|
90 |
+
if not filtered_results:
|
91 |
+
html_output += "<p>No news results found within the last 24 hours.</p>"
|
92 |
+
else:
|
93 |
+
for result in filtered_results:
|
94 |
+
html_output += f"""
|
95 |
+
<div class="news-item">
|
96 |
+
<a href="{result.get('url', '#')}" class="news-title">{result.get('title', 'No Title')}</a>
|
97 |
+
<p class="news-snippet">{result.get('snippet', 'No Snippet')}</p>
|
98 |
+
<p class="news-meta">Source: {result.get('channel', 'Unknown')} - {result.get('time', 'Unknown time')}</p>
|
99 |
+
</div>
|
100 |
+
"""
|
101 |
else:
|
102 |
+
html_output += f"<p>Unexpected response format: {type(results)}</p>"
|
103 |
+
except Exception as e:
|
104 |
+
html_output += f"<p>Error processing results: {str(e)}</p>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
html_output += "</div>"
|
107 |
return html_output
|