删除日志文件改为print方便docker调试、 API_URL处理逻辑变更、akshare保持最新版本号
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -42,6 +30,7 @@ def analyze():
|
||||
|
||||
return jsonify({'results': results})
|
||||
except Exception as e:
|
||||
print(f"分析股票时出错: {str(e)}")
|
||||
return jsonify({'error': str(e)}), 500
|
||||
|
||||
@app.route('/search_us_stocks', methods=['GET'])
|
||||
@@ -55,11 +44,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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user