Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -105,16 +105,19 @@ def serve_frontend():
|
|
| 105 |
# API endpoint
|
| 106 |
@app.route('/news', methods=['GET'])
|
| 107 |
def get_news():
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
if __name__ == "__main__":
|
| 120 |
app.run(host="0.0.0.0", port=7860)
|
|
|
|
| 105 |
# API endpoint
|
| 106 |
@app.route('/news', methods=['GET'])
|
| 107 |
def get_news():
|
| 108 |
+
try:
|
| 109 |
+
topics = request.args.get('topics', 'all')
|
| 110 |
+
if topics == 'all':
|
| 111 |
+
selected_topics = TOPICS
|
| 112 |
+
else:
|
| 113 |
+
selected_topics = [t.strip() for t in topics.split(',') if t.strip() in TOPICS]
|
| 114 |
+
if not selected_topics:
|
| 115 |
+
return jsonify({"error": "Invalid topics"}), 400
|
| 116 |
+
articles = fetch_news(selected_topics, total_articles=2, model_index=0)
|
| 117 |
+
return jsonify({"articles": articles, "last_updated": datetime.now().strftime("%Y-%m-%d %H:%M:%S")})
|
| 118 |
+
except Exception as e:
|
| 119 |
+
print(f"Error in get_news: {str(e)}")
|
| 120 |
+
return jsonify({"error": f"Server error: {str(e)}"}), 500
|
| 121 |
|
| 122 |
if __name__ == "__main__":
|
| 123 |
app.run(host="0.0.0.0", port=7860)
|