security: 将敏感配置移至配置文件
This commit is contained in:
parent
879cee5f68
commit
a726496c54
2
.gitignore
vendored
2
.gitignore
vendored
@ -36,3 +36,5 @@ config.json
|
|||||||
*.log
|
*.log
|
||||||
.env
|
.env
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
stock_cache.json
|
||||||
|
watchlist.json
|
||||||
@ -11,7 +11,7 @@ Config.ensure_directories()
|
|||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
# 设置tushare token
|
# 设置tushare token
|
||||||
ts.set_token(Config.TUSHARE_TOKEN)
|
ts.set_token(Config.get_tushare_token())
|
||||||
pro = ts.pro_api()
|
pro = ts.pro_api()
|
||||||
|
|
||||||
# Mount static files
|
# Mount static files
|
||||||
|
|||||||
@ -1,13 +1,11 @@
|
|||||||
import os
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
# 基础配置
|
# 基础配置
|
||||||
class Config:
|
class Config:
|
||||||
# 项目根目录
|
# 项目根目录
|
||||||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
# Tushare API配置
|
|
||||||
TUSHARE_TOKEN = '90f8a141125e1decb952cd49032b7b8409a2d7fa370745f6c9f45c96'
|
|
||||||
|
|
||||||
# 配置文件路径
|
# 配置文件路径
|
||||||
CONFIG_FILE = os.path.join(BASE_DIR, "config.json")
|
CONFIG_FILE = os.path.join(BASE_DIR, "config.json")
|
||||||
|
|
||||||
@ -17,6 +15,29 @@ class Config:
|
|||||||
# 静态文件目录
|
# 静态文件目录
|
||||||
STATIC_DIR = os.path.join(BASE_DIR, "app", "static")
|
STATIC_DIR = os.path.join(BASE_DIR, "app", "static")
|
||||||
|
|
||||||
|
# API配置
|
||||||
|
@classmethod
|
||||||
|
def load_config(cls):
|
||||||
|
if os.path.exists(cls.CONFIG_FILE):
|
||||||
|
with open(cls.CONFIG_FILE, 'r', encoding='utf-8') as f:
|
||||||
|
return json.load(f)
|
||||||
|
return {"watchlist": {}}
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_tushare_token(cls):
|
||||||
|
config = cls.load_config()
|
||||||
|
return config.get('tushare_token')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_ai_api_key(cls):
|
||||||
|
config = cls.load_config()
|
||||||
|
return config.get('ai_api_key')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_ai_model_id(cls):
|
||||||
|
config = cls.load_config()
|
||||||
|
return config.get('ai_model_id')
|
||||||
|
|
||||||
# 确保目录存在
|
# 确保目录存在
|
||||||
@classmethod
|
@classmethod
|
||||||
def ensure_directories(cls):
|
def ensure_directories(cls):
|
||||||
|
|||||||
@ -2,12 +2,13 @@ import json
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
from openai import OpenAI
|
from openai import OpenAI
|
||||||
|
from app.config import Config
|
||||||
|
|
||||||
class AIAnalysisService:
|
class AIAnalysisService:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.model = "ep-20250111143839-vn8l8" # endpoint ID
|
self.model = Config.get_ai_model_id() # 从配置获取 model ID
|
||||||
self.client = OpenAI(
|
self.client = OpenAI(
|
||||||
api_key = "cf4edd4d-55cd-4e0f-82f6-49072660bdaf", # 直接使用API Key
|
api_key = Config.get_ai_api_key(), # 从配置获取 API Key
|
||||||
base_url = "https://ark.cn-beijing.volces.com/api/v3"
|
base_url = "https://ark.cn-beijing.volces.com/api/v3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,6 @@
|
|||||||
{
|
{
|
||||||
"watchlist": {},
|
"watchlist": {},
|
||||||
"tushare_token": "your_tushare_token_here"
|
"tushare_token": "your_tushare_token_here",
|
||||||
|
"ai_api_key": "your_ai_api_key_here",
|
||||||
|
"ai_model_id": "your_ai_model_id_here"
|
||||||
}
|
}
|
||||||
@ -1,54 +1,11 @@
|
|||||||
aiofiles==23.2.1
|
|
||||||
akshare==1.11.22
|
|
||||||
annotated-types==0.7.0
|
|
||||||
anyio==3.7.1
|
|
||||||
baostock==0.8.9
|
|
||||||
beautifulsoup4==4.12.3
|
|
||||||
bs4==0.0.2
|
|
||||||
certifi==2024.12.14
|
|
||||||
charset-normalizer==3.4.1
|
|
||||||
click==8.1.8
|
|
||||||
decorator==5.1.1
|
|
||||||
efinance==0.4.8
|
|
||||||
et_xmlfile==2.0.0
|
|
||||||
fastapi==0.104.1
|
fastapi==0.104.1
|
||||||
h11==0.14.0
|
|
||||||
html5lib==1.1
|
|
||||||
idna==3.10
|
|
||||||
Jinja2==3.1.2
|
|
||||||
jsonpath==0.82.2
|
|
||||||
lxml==5.3.0
|
|
||||||
markdown-it-py==3.0.0
|
|
||||||
MarkupSafe==3.0.2
|
|
||||||
mdurl==0.1.2
|
|
||||||
multitasking==0.0.11
|
|
||||||
numpy==2.2.1
|
|
||||||
openpyxl==3.1.5
|
|
||||||
pandas==2.2.3
|
|
||||||
py==1.11.0
|
|
||||||
py_mini_racer==0.6.0
|
|
||||||
pydantic==2.10.4
|
|
||||||
pydantic_core==2.27.2
|
|
||||||
Pygments==2.19.1
|
|
||||||
pypinyin==0.53.0
|
|
||||||
python-dateutil==2.9.0.post0
|
|
||||||
python-multipart==0.0.6
|
|
||||||
pytz==2024.2
|
|
||||||
requests==2.32.3
|
|
||||||
retry==0.9.2
|
|
||||||
rich==13.9.4
|
|
||||||
simplejson==3.19.3
|
|
||||||
six==1.17.0
|
|
||||||
sniffio==1.3.1
|
|
||||||
soupsieve==2.6
|
|
||||||
starlette==0.27.0
|
|
||||||
tabulate==0.9.0
|
|
||||||
tqdm==4.67.1
|
|
||||||
tushare==1.4.16
|
|
||||||
typing_extensions==4.12.2
|
|
||||||
tzdata==2024.2
|
|
||||||
urllib3==2.3.0
|
|
||||||
uvicorn==0.24.0
|
uvicorn==0.24.0
|
||||||
webencodings==0.5.1
|
python-multipart==0.0.6
|
||||||
websocket-client==1.8.0
|
pydantic==2.10.4
|
||||||
xlrd==2.0.1
|
requests==2.32.3
|
||||||
|
pandas==2.2.3
|
||||||
|
numpy==2.2.1
|
||||||
|
tushare==1.4.16
|
||||||
|
Jinja2==3.1.2
|
||||||
|
python-dateutil==2.9.0.post0
|
||||||
|
simplejson==3.19.3
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user