新增素材更新功能
This commit is contained in:
@@ -10,11 +10,13 @@ from app.models.upload_task import UploadTask
|
||||
from app.models.generated_resource import GeneratedResource
|
||||
from app.models.user_oauth import UserOAuth
|
||||
from app.models.resources_material import ResourcesMaterial
|
||||
from app.models.user_oauth_account import UserOAuthAccount
|
||||
from app.utils.id_gen import generate_id
|
||||
from app.utils.douyinApi import DouyinApi
|
||||
|
||||
import os
|
||||
import hashlib
|
||||
import json
|
||||
|
||||
LOG_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), "logs")
|
||||
|
||||
@@ -133,6 +135,51 @@ class UploadQueue:
|
||||
note=result.get("message", "上传成功"),
|
||||
)
|
||||
)
|
||||
|
||||
#请求巨量接口获取账户信息,如果存在则更新,否则插入新记录
|
||||
param = {
|
||||
"account_ids" : json.dumps([int(task.advertiser_id)]),
|
||||
}
|
||||
try:
|
||||
account_info = await douyin_api.get_account_info(task.oauth_id, param)
|
||||
|
||||
code = account_info.get("code", 0)
|
||||
try:
|
||||
code = int(code)
|
||||
except (ValueError, TypeError):
|
||||
code = -1
|
||||
|
||||
if code != 0:
|
||||
logger.error(f"Error getting account info: {json.dumps(account_info)}")
|
||||
else:
|
||||
existing_account = await db.execute(
|
||||
select(UserOAuthAccount).where(
|
||||
UserOAuthAccount.oauth_id == task.oauth_id,
|
||||
UserOAuthAccount.advertiser_id == task.advertiser_id,
|
||||
)
|
||||
)
|
||||
existing_account = existing_account.scalar_one_or_none()
|
||||
|
||||
if existing_account:
|
||||
await db.execute(
|
||||
update(UserOAuthAccount).where(
|
||||
UserOAuthAccount.id == existing_account.id,
|
||||
).values(
|
||||
deleted_at=None,
|
||||
advertiser_name= account_info.get("data", {}).get("account_detail_list", [{}])[0].get("advertiser_name", ""),
|
||||
advertiser_role= "",
|
||||
)
|
||||
)
|
||||
else:
|
||||
db.add(UserOAuthAccount(
|
||||
id=generate_id(),
|
||||
oauth_id=task.oauth_id,
|
||||
advertiser_id=task.advertiser_id,
|
||||
advertiser_name= account_info.get("data", {}).get("account_detail_list", [{}])[0].get("advertiser_name", ""),
|
||||
advertiser_role= "",
|
||||
))
|
||||
except Exception as e:
|
||||
logger.error(f"Exception getting account info: {e}")
|
||||
else:
|
||||
await db.execute(
|
||||
update(UploadTask).where(UploadTask.id == task_id).values(
|
||||
|
||||
Reference in New Issue
Block a user