Refactor and translate comments and docstrings in utility modules to English for better clarity and maintainability. Update Gunicorn and application startup messages for consistency in language. Enhance documentation with English translations for better accessibility.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""
|
||||
配置模块
|
||||
统一导出所有配置
|
||||
Configuration module
|
||||
Export all configurations uniformly
|
||||
"""
|
||||
from app.config.settings import Config
|
||||
from app.config.api_keys import APIKeys
|
||||
@@ -15,17 +15,17 @@ from app.config.data_sources import (
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
# 主配置
|
||||
# main configuration
|
||||
'Config',
|
||||
|
||||
# API 密钥
|
||||
# API key
|
||||
'APIKeys',
|
||||
|
||||
# 数据库/缓存
|
||||
# Database/cache
|
||||
'RedisConfig',
|
||||
'CacheConfig',
|
||||
|
||||
# 数据源
|
||||
# data source
|
||||
'DataSourceConfig',
|
||||
'FinnhubConfig',
|
||||
'TiingoConfig',
|
||||
|
||||
@@ -5,8 +5,7 @@ All third-party keys should be provided via environment variables (recommended:
|
||||
import os
|
||||
|
||||
class MetaAPIKeys(type):
|
||||
"""API Keys 元类,用于支持类属性的动态获取"""
|
||||
|
||||
"""API Keys metaclass, used to support dynamic acquisition of class attributes"""
|
||||
@property
|
||||
def FINNHUB_API_KEY(cls):
|
||||
from app.utils.config_loader import load_addon_config
|
||||
@@ -95,18 +94,18 @@ class MetaAPIKeys(type):
|
||||
|
||||
|
||||
class APIKeys(metaclass=MetaAPIKeys):
|
||||
"""API 密钥配置类"""
|
||||
|
||||
"""API key configuration class"""
|
||||
|
||||
@classmethod
|
||||
def get(cls, key_name: str, default: str = '') -> str:
|
||||
"""获取 API 密钥"""
|
||||
# 尝试从类属性获取
|
||||
"""Get API key"""
|
||||
# Try to get from class attribute
|
||||
if hasattr(cls, key_name):
|
||||
return getattr(cls, key_name)
|
||||
return default
|
||||
|
||||
@classmethod
|
||||
def is_configured(cls, key_name: str) -> bool:
|
||||
"""检查 API 密钥是否已配置"""
|
||||
"""Check if the API key is configured"""
|
||||
value = cls.get(key_name)
|
||||
return bool(value and value.strip())
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
数据源配置
|
||||
Data source configuration
|
||||
"""
|
||||
import os
|
||||
|
||||
@@ -24,7 +24,7 @@ class MetaDataSourceConfig(type):
|
||||
|
||||
|
||||
class DataSourceConfig(metaclass=MetaDataSourceConfig):
|
||||
"""数据源通用配置"""
|
||||
"""General data source configuration."""
|
||||
pass
|
||||
|
||||
|
||||
@@ -51,9 +51,7 @@ class MetaFinnhubConfig(type):
|
||||
|
||||
|
||||
class FinnhubConfig(metaclass=MetaFinnhubConfig):
|
||||
"""Finnhub 数据源配置"""
|
||||
pass
|
||||
|
||||
"""Finnhub data source configuration"""
|
||||
|
||||
class MetaTiingoConfig(type):
|
||||
@property
|
||||
@@ -68,9 +66,7 @@ class MetaTiingoConfig(type):
|
||||
|
||||
|
||||
class TiingoConfig(metaclass=MetaTiingoConfig):
|
||||
"""Tiingo 数据源配置"""
|
||||
pass
|
||||
|
||||
"""Tiingo data source configuration"""
|
||||
|
||||
class MetaYFinanceConfig(type):
|
||||
@property
|
||||
@@ -94,9 +90,7 @@ class MetaYFinanceConfig(type):
|
||||
|
||||
|
||||
class YFinanceConfig(metaclass=MetaYFinanceConfig):
|
||||
"""Yahoo Finance 数据源配置"""
|
||||
pass
|
||||
|
||||
"""Yahoo Finance data source configuration"""
|
||||
|
||||
class MetaCCXTConfig(type):
|
||||
@property
|
||||
@@ -146,7 +140,7 @@ class MetaCCXTConfig(type):
|
||||
|
||||
|
||||
class CCXTConfig(metaclass=MetaCCXTConfig):
|
||||
"""CCXT 加密货币数据源配置"""
|
||||
"""CCXT cryptocurrency data source configuration."""
|
||||
pass
|
||||
|
||||
|
||||
@@ -166,5 +160,4 @@ class MetaAkshareConfig(type):
|
||||
|
||||
|
||||
class AkshareConfig(metaclass=MetaAkshareConfig):
|
||||
"""Akshare 数据源配置"""
|
||||
pass
|
||||
"""Akshare data source configuration"""
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
"""
|
||||
数据库和缓存配置
|
||||
Database and cache configuration
|
||||
"""
|
||||
import os
|
||||
|
||||
class MetaRedisConfig(type):
|
||||
"""Redis 配置"""
|
||||
|
||||
"""Redis configuration"""
|
||||
@property
|
||||
def HOST(cls):
|
||||
return os.getenv('REDIS_HOST', 'localhost')
|
||||
@@ -36,22 +35,21 @@ class MetaRedisConfig(type):
|
||||
|
||||
|
||||
class RedisConfig(metaclass=MetaRedisConfig):
|
||||
"""Redis 缓存配置"""
|
||||
|
||||
"""Redis cache configuration."""
|
||||
|
||||
@classmethod
|
||||
def get_url(cls) -> str:
|
||||
"""获取 Redis 连接 URL"""
|
||||
"""Get the Redis connection URL."""
|
||||
if cls.PASSWORD:
|
||||
return f"redis://:{cls.PASSWORD}@{cls.HOST}:{cls.PORT}/{cls.DB}"
|
||||
return f"redis://{cls.HOST}:{cls.PORT}/{cls.DB}"
|
||||
|
||||
|
||||
class MetaCacheConfig(type):
|
||||
"""缓存业务配置"""
|
||||
|
||||
@property
|
||||
"""Cache business configuration."""
|
||||
|
||||
def ENABLED(cls):
|
||||
# 强制默认关闭,除非环境变量显式开启
|
||||
# Forced to be off by default unless explicitly enabled by an environment variable
|
||||
return os.getenv('CACHE_ENABLED', 'False').lower() == 'true'
|
||||
|
||||
@property
|
||||
@@ -61,15 +59,15 @@ class MetaCacheConfig(type):
|
||||
@property
|
||||
def KLINE_CACHE_TTL(cls):
|
||||
return {
|
||||
'1m': 5, # 1分钟K线缓存5秒
|
||||
'3m': 30, # 3分钟K线缓存30秒
|
||||
'5m': 60, # 5分钟K线缓存1分钟
|
||||
'15m': 300, # 15分钟K线缓存5分钟
|
||||
'30m': 300, # 30分钟K线缓存5分钟
|
||||
'1H': 300, # 1小时K线缓存5分钟
|
||||
'4H': 300, # 4小时K线缓存5分钟
|
||||
'1D': 300, # 日K线缓存5分钟
|
||||
# 兼容小写
|
||||
'1m': 5, # K-line cache for 1 minute and 5 seconds
|
||||
'3m': 30, # 3 minutes K-line cache 30 seconds
|
||||
'5m': 60, # 5 minutes K-line cache 1 minute
|
||||
'15m': 300, # 15 minutes K-line cache 5 minutes
|
||||
'30m': 300, # 30 minutes K-line cache 5 minutes
|
||||
'1H': 300, # 1 hour K-line cache for 5 minutes
|
||||
'4H': 300, # 4 hours K-line cache for 5 minutes
|
||||
'1D': 300, # Daily K-line cache for 5 minutes
|
||||
# Compatible with lowercase
|
||||
'1h': 300,
|
||||
'4h': 300,
|
||||
'1d': 300,
|
||||
@@ -85,5 +83,5 @@ class MetaCacheConfig(type):
|
||||
|
||||
|
||||
class CacheConfig(metaclass=MetaCacheConfig):
|
||||
"""缓存配置"""
|
||||
"""Cache configuration."""
|
||||
pass
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
"""
|
||||
应用主配置
|
||||
Apply main configuration
|
||||
"""
|
||||
import os
|
||||
|
||||
class MetaConfig(type):
|
||||
# ==================== 服务配置 ====================
|
||||
# 服务启动参数通常由环境变量或命令行参数决定,不建议从数据库读取
|
||||
# ==================== Service Configuration ====================
|
||||
# Service startup parameters are usually determined by environment variables or command line parameters. Reading from the database is not recommended.
|
||||
|
||||
@property
|
||||
def HOST(cls):
|
||||
@@ -27,7 +27,7 @@ class MetaConfig(type):
|
||||
def VERSION(cls):
|
||||
return '2.0.0'
|
||||
|
||||
# ==================== 认证配置 ====================
|
||||
# ==================== Authentication configuration ====================
|
||||
@property
|
||||
def SECRET_KEY(cls):
|
||||
return os.getenv('SECRET_KEY', 'quantdinger-secret-key-change-me')
|
||||
@@ -40,8 +40,8 @@ class MetaConfig(type):
|
||||
def ADMIN_PASSWORD(cls):
|
||||
return os.getenv('ADMIN_PASSWORD', '123456')
|
||||
|
||||
# ==================== 日志配置 ====================
|
||||
# 日志配置通常在应用启动最早阶段需要,建议保持环境变量
|
||||
# ==================== Log configuration ====================
|
||||
# Log configuration is usually required at the earliest stage of application startup. It is recommended to maintain environment variables.
|
||||
|
||||
@property
|
||||
def LOG_LEVEL(cls):
|
||||
@@ -63,7 +63,7 @@ class MetaConfig(type):
|
||||
def LOG_BACKUP_COUNT(cls):
|
||||
return int(os.getenv('LOG_BACKUP_COUNT', 5))
|
||||
|
||||
# ==================== 安全配置 ====================
|
||||
# ==================== Security Configuration ====================
|
||||
|
||||
@property
|
||||
def RATE_LIMIT(cls):
|
||||
@@ -71,7 +71,7 @@ class MetaConfig(type):
|
||||
val = load_addon_config().get('app', {}).get('rate_limit')
|
||||
return int(val) if val is not None else int(os.getenv('RATE_LIMIT', 100))
|
||||
|
||||
# ==================== 功能开关 ====================
|
||||
# ==================== Function switch ====================
|
||||
|
||||
@property
|
||||
def ENABLE_CACHE(cls):
|
||||
@@ -90,9 +90,9 @@ class MetaConfig(type):
|
||||
return os.getenv('ENABLE_REQUEST_LOG', 'True').lower() == 'true'
|
||||
|
||||
class Config(metaclass=MetaConfig):
|
||||
"""应用配置类"""
|
||||
|
||||
"""Application configuration class."""
|
||||
|
||||
@classmethod
|
||||
def get_log_path(cls) -> str:
|
||||
"""获取日志文件完整路径"""
|
||||
"""Get the full path of the log file."""
|
||||
return os.path.join(cls.LOG_DIR, cls.LOG_FILE)
|
||||
|
||||
Reference in New Issue
Block a user