添加账号删除功能
This commit is contained in:
parent
7be55dc059
commit
231526c1ff
|
|
@ -18,12 +18,9 @@ class DealAccount:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
async def delete_account(self, params: List[str]):
|
async def delete_account(self, params: Dict[str, Any]):
|
||||||
"""删除账户"""
|
"""删除账户"""
|
||||||
if len(params) == 1:
|
condition = "account_id='{}' and app_name='{}'".format(params["account_id"], params["app_name"])
|
||||||
condition = "account_id={}".format(params[0])
|
|
||||||
else:
|
|
||||||
condition = f"account_id in ({','.join(params)})"
|
|
||||||
await self.db_pool.initialize()
|
await self.db_pool.initialize()
|
||||||
result = await self.db_pool.delete(table="crawler_account_record_info", where_conditions=condition)
|
result = await self.db_pool.delete(table="crawler_account_record_info", where_conditions=condition)
|
||||||
if result:
|
if result:
|
||||||
|
|
|
||||||
20
main.py
20
main.py
|
|
@ -8,7 +8,7 @@ from typing import Dict, Any, Optional, List
|
||||||
from fastapi import FastAPI, HTTPException, Depends
|
from fastapi import FastAPI, HTTPException, Depends
|
||||||
|
|
||||||
from public_function.public_func import read_config
|
from public_function.public_func import read_config
|
||||||
from model.model import AccountCreate, AccountUpdate, CrawlerTask
|
from model.model import AccountCreate, AccountUpdate, CrawlerTask, AccountDelete
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
|
|
@ -87,6 +87,24 @@ async def add_account(account_data: AccountCreate, account_manager: Any = Depend
|
||||||
raise HTTPException(status_code=500, detail="新增账号失败,失败原因:{}".format(e))
|
raise HTTPException(status_code=500, detail="新增账号失败,失败原因:{}".format(e))
|
||||||
|
|
||||||
|
|
||||||
|
@app.post("/delete_account", summary="新增账号")
|
||||||
|
async def delete_account(account_data: AccountDelete, account_manager: Any = Depends(get_account_manager)):
|
||||||
|
"""
|
||||||
|
删除爬虫账号
|
||||||
|
- **account_id**: 账号ID
|
||||||
|
- **password**: 密码
|
||||||
|
- **app_name**: 应用名称
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
print(account_data.dict())
|
||||||
|
# 这里应该调用实际的添加账号方法
|
||||||
|
result = await account_manager.delete_account(account_data.dict())
|
||||||
|
return {"code": 200, "message": "删除账号成功", "data": result}
|
||||||
|
except Exception as e:
|
||||||
|
print(f"新增账号失败: {e}")
|
||||||
|
raise HTTPException(status_code=500, detail="删除账号失败,请重试,失败原因:{}".format(e))
|
||||||
|
|
||||||
|
|
||||||
@app.post("/receive_data")
|
@app.post("/receive_data")
|
||||||
async def receive_data(params: Dict[str, Any]):
|
async def receive_data(params: Dict[str, Any]):
|
||||||
"""数据接收接口"""
|
"""数据接收接口"""
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,11 @@ class AccountUpdate(BaseModel):
|
||||||
status: int = Field(..., ge=1, le=2, description="状态:1-空闲,2-使用中")
|
status: int = Field(..., ge=1, le=2, description="状态:1-空闲,2-使用中")
|
||||||
|
|
||||||
|
|
||||||
|
class AccountDelete(BaseModel):
|
||||||
|
account_id: str = Field(..., min_length=1, max_length=128, description="账号ID")
|
||||||
|
app_name: str = Field(..., min_length=1, max_length=128, description="应用名称")
|
||||||
|
|
||||||
|
|
||||||
class CrawlerTask(BaseModel):
|
class CrawlerTask(BaseModel):
|
||||||
country: str = Field(..., min_length=1, max_length=128, description="账号所在国家")
|
country: str = Field(..., min_length=1, max_length=128, description="账号所在国家")
|
||||||
app_name: str = Field(..., min_length=1, max_length=128, description="应用名称")
|
app_name: str = Field(..., min_length=1, max_length=128, description="应用名称")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue