代码优化
This commit is contained in:
parent
980f6245d1
commit
6aa3999af7
16
main.py
16
main.py
|
|
@ -7,6 +7,8 @@ from pathlib import Path
|
||||||
from typing import Dict, Any, Optional, List
|
from typing import Dict, Any, Optional, List
|
||||||
from fastapi import FastAPI, HTTPException, Depends, Header
|
from fastapi import FastAPI, HTTPException, Depends, Header
|
||||||
from public_function.auth import verify_tk_token
|
from public_function.auth import verify_tk_token
|
||||||
|
from task_management.all_task_management import AllTask
|
||||||
|
from account_management.deal_account import DealAccount
|
||||||
from public_function.public_func import read_config, create_logger
|
from public_function.public_func import read_config, create_logger
|
||||||
from model.model import GoodsInfo, DataReceive, AccountStatus, AccountUpdate, TokenItem, CrawlerItem, ResetTask, AccountObtain
|
from model.model import GoodsInfo, DataReceive, AccountStatus, AccountUpdate, TokenItem, CrawlerItem, ResetTask, AccountObtain
|
||||||
|
|
||||||
|
|
@ -20,7 +22,6 @@ def get_config():
|
||||||
config_path = os.path.join(Path(__file__).resolve().parent, 'public_function/config.yaml')
|
config_path = os.path.join(Path(__file__).resolve().parent, 'public_function/config.yaml')
|
||||||
try:
|
try:
|
||||||
# 这里假设read_config函数存在
|
# 这里假设read_config函数存在
|
||||||
from public_function.public_func import read_config
|
|
||||||
return read_config(config_path)
|
return read_config(config_path)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print(f"未找到read_config函数,使用默认配置")
|
print(f"未找到read_config函数,使用默认配置")
|
||||||
|
|
@ -31,7 +32,6 @@ def get_account_manager():
|
||||||
"""获取账号管理器实例"""
|
"""获取账号管理器实例"""
|
||||||
config = get_config()
|
config = get_config()
|
||||||
try:
|
try:
|
||||||
from account_management.deal_account import DealAccount
|
|
||||||
return DealAccount(config)
|
return DealAccount(config)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print(f"未找到DealAccount类,返回模拟实例")
|
print(f"未找到DealAccount类,返回模拟实例")
|
||||||
|
|
@ -42,24 +42,12 @@ def get_task_manager():
|
||||||
"""任务获取管理器实例"""
|
"""任务获取管理器实例"""
|
||||||
config = get_config()
|
config = get_config()
|
||||||
try:
|
try:
|
||||||
from task_management.all_task_management import AllTask
|
|
||||||
return AllTask(config)
|
return AllTask(config)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print(f"未找到AllTask类,返回模拟实例")
|
print(f"未找到AllTask类,返回模拟实例")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def get_reset_manager():
|
|
||||||
"""设备重置管理器"""
|
|
||||||
config = get_config()
|
|
||||||
try:
|
|
||||||
from task_management.all_task_management import AllTask
|
|
||||||
return AllTask(config)
|
|
||||||
except ImportError:
|
|
||||||
print("未找到 类,返回模拟实例")
|
|
||||||
return None
|
|
||||||
|
|
||||||
|
|
||||||
# 账号处理相关
|
# 账号处理相关
|
||||||
@app.post("/obtain_account", summary="获取可用账号")
|
@app.post("/obtain_account", summary="获取可用账号")
|
||||||
async def obtain_account(account_data: AccountObtain, account_manager: Any = Depends(get_account_manager)):
|
async def obtain_account(account_data: AccountObtain, account_manager: Any = Depends(get_account_manager)):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue