This commit is contained in:
Cassianvale
2025-03-04 11:55:47 +08:00
4 changed files with 24 additions and 34 deletions

View File

@@ -2,26 +2,14 @@ from flask import Flask, render_template, request, jsonify
from stock_analyzer import StockAnalyzer
from us_stock_service import USStockService
import threading
import logging
from logging.handlers import RotatingFileHandler
import traceback
import os
app = Flask(__name__)
analyzer = StockAnalyzer()
us_stock_service = USStockService()
# 配置日志
logging.basicConfig(level=logging.INFO)
handler = RotatingFileHandler('flask_app.log', maxBytes=10000000, backupCount=5)
handler.setFormatter(logging.Formatter(
'[%(asctime)s] %(levelname)s in %(module)s: %(message)s'
))
app.logger.addHandler(handler)
@app.route('/')
def index():
# 如果环境变量不存在或为空,返回 None
announcement = os.getenv('ANNOUNCEMENT_TEXT') or None
return render_template('index.html', announcement=announcement)
@@ -50,8 +38,7 @@ def analyze():
return jsonify({'results': results})
except Exception as e:
app.logger.error(f"处理请求失败: {str(e)}")
app.logger.error(f"详细错误: {traceback.format_exc()}")
print(f"分析股票时出错: {str(e)}")
return jsonify({'error': str(e)}), 500
@app.route('/search_us_stocks', methods=['GET'])
@@ -65,11 +52,11 @@ def search_us_stocks():
return jsonify({'results': results})
except Exception as e:
app.logger.error(f"搜索美股代码时出错: {str(e)}")
print(f"搜索美股代码时出错: {str(e)}")
return jsonify({'error': str(e)}), 500
if __name__ == '__main__':
# 将 host 设置为 '0.0.0.0' 使其支持所有网络接口访问
app.run(host='0.0.0.0', port=8888, debug=True)