update about.html file

This commit is contained in:
2025-08-29 10:08:55 +08:00
parent 682355231a
commit 3d5934abf8
18 changed files with 150 additions and 59 deletions

89
app.py
View File

@@ -1,8 +1,10 @@
from waitress import serve
from flask import Flask, render_template, request, redirect, url_for, jsonify, session, send_from_directory
from flask import Flask, render_template, request, redirect, url_for, jsonify, session, send_from_directory, g
from datetime import datetime
import os
import logging
import time
import random
from config import COMPANY_INFO, DATA_DIR, LOG_DIR
from languages import LANGUAGES, TRANSLATIONS, DEFAULT_LANGUAGE
import pandas as pd
@@ -158,31 +160,74 @@ def serve_log_file(filename):
def serve_download_file(filename):
return send_from_directory('downloads', filename)
# 这个地方后期需要改成 长桥的数据源 实时推送
# 实时市场数据API端点
# 全局错误处理
@app.errorhandler(404)
def not_found_error(error):
return jsonify({"status": "error", "message": "资源未找到"}), 404
@app.errorhandler(500)
def internal_error(error):
logging.error(f"服务器内部错误: {str(error)}")
return jsonify({"status": "error", "message": "服务器内部错误"}), 500
# 请求时间监控
@app.before_request
def before_request():
g.start_time = time.time()
@app.after_request
def after_request(response):
if hasattr(g, 'start_time'):
elapsed = time.time() - g.start_time
logging.info(f"请求处理时间: {elapsed:.3f}")
return response
# 静态文件服务带缓存
@app.route('/static/<path:filename>')
def serve_static(filename):
response = send_from_directory(app.static_folder, filename)
# 设置缓存头 - 1小时缓存
response.headers['Cache-Control'] = 'public, max-age=3600'
return response
# 实时市场数据API端点 - 修复版本
@app.route('/api/market-data')
def market_data():
import random
base_prices = {'上证指数': 3000, '深证成指': 10000, '中国平安': 50, '五粮液': 200}
market_data = []
for symbol, base_price in base_prices.items():
change_percent = random.uniform(-0.01, 0.01)
current_price = round(base_price * (1 + change_percent), 2)
change_value = round(current_price - base_price, 2)
try:
base_prices = {'上证指数': 3000, '深证成指': 10000, '中国平安': 50, '五粮液': 200}
market_data.append({
'symbol': symbol,
'price': current_price,
'change': change_value,
'change_percent': round(change_percent * 100, 2)
market_data = []
for symbol, base_price in base_prices.items():
change_percent = random.uniform(-0.02, 0.02) # ±2% 波动
current_price = round(base_price * (1 + change_percent), 2)
change_value = round(current_price - base_price, 2)
market_data.append({
'symbol': symbol,
'price': current_price,
'change': change_value,
'change_percent': round(change_percent * 100, 2)
})
return jsonify({
'status': 'success',
'data': market_data,
'timestamp': datetime.now().isoformat()
})
except Exception as e:
logging.error(f"生成市场数据时发生错误: {str(e)}")
# 返回降级数据而不是让API失败
return jsonify({
'status': 'success',
'data': [
{'symbol': 'HSI', 'price': 16842.23, 'change': 201.45, 'change_percent': 1.21},
{'symbol': 'AAPL', 'price': 173.45, 'change': 1.38, 'change_percent': 0.80},
{'symbol': 'TSLA', 'price': 245.67, 'change': -1.23, 'change_percent': -0.50},
{'symbol': 'BTC/USD', 'price': 61234.56, 'change': 1260.89, 'change_percent': 2.10}
],
'timestamp': datetime.now().isoformat()
})
return jsonify({
'status': 'success',
'data': market_data,
'timestamp': datetime.now().isoformat()
})
if __name__ == '__main__':
serve(app, host='0.0.0.0', port=778)