ayush2917 commited on
Commit
4660c51
·
verified ·
1 Parent(s): 99379e2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -10
app.py CHANGED
@@ -105,16 +105,19 @@ def serve_frontend():
105
  # API endpoint
106
  @app.route('/news', methods=['GET'])
107
  def get_news():
108
- topics = request.args.get('topics', 'all')
109
- if topics == 'all':
110
- selected_topics = TOPICS
111
- else:
112
- selected_topics = [t.strip() for t in topics.split(',') if t.strip() in TOPICS]
113
- if not selected_topics:
114
- return jsonify({"error": "Invalid topics"}), 400
115
-
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
 
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)