feat(monitor): 作品模式也采博主粉丝数,从作品详情的 author 里拿
超级编导导入的是作品模式任务,从不问 user/profile,所以这些任务里每个博主 的粉丝数都是空的 —— 而运营要看的就是「这批号多大」。(之前只补了主页链接。) 详情返回的 author 里现成有 follower_count / total_favorited / following_count,白拿的,不需要多发请求。aweme_count 实测是 null,作品数 留 None —— 为一个数字给每个博主多打一次资料接口不划算。 字段缺失时留 None 而不是 0:「粉丝 0」和「没采到」不是一回事。author 是 精简版(字段全缺)时不写快照行,免得界面上出现「有采集时间、没有数字」。
This commit is contained in:
@@ -205,6 +205,12 @@ async def _collect_batch(
|
||||
except douyin_api.DouyinApiError as exc:
|
||||
errors.append(f"拉取作品 {external_id} 失败:{exc}")
|
||||
videos = []
|
||||
# 作品详情里带着作者的粉丝/总获赞。作品模式**不会**单独问博主资料 ——
|
||||
# 不从这里收一份,这类任务(超级编导导入的都在这里)的博主粉丝数永远是空的。
|
||||
for video in videos:
|
||||
profile = _profile_from_author(video)
|
||||
if profile is not None:
|
||||
profiles.append(profile)
|
||||
else:
|
||||
videos = await _creator_works(
|
||||
external_id,
|
||||
@@ -250,6 +256,36 @@ async def _collect_batch(
|
||||
}
|
||||
|
||||
|
||||
def _profile_from_author(video: Dict[str, Any]) -> Optional[Dict[str, Any]]:
|
||||
"""把作品详情里那份 author 拼成一条账号快照;什么都不全就返回 None。
|
||||
|
||||
只在**有值**时收:author 对象偶尔是精简版(只有 uid/nickname),那种情况下写一条
|
||||
全 NULL 的快照没有意义,还会让界面显示「采集时间有、数字没有」。
|
||||
"""
|
||||
creator_hash = str(video.get("creator_hash") or "")
|
||||
if not creator_hash:
|
||||
return None
|
||||
|
||||
stats = (
|
||||
video.get("creator_fans"),
|
||||
video.get("creator_total_favorited"),
|
||||
video.get("creator_works"),
|
||||
video.get("creator_following"),
|
||||
)
|
||||
if all(value is None for value in stats):
|
||||
return None
|
||||
|
||||
return {
|
||||
"creator_hash": creator_hash,
|
||||
"creator_id": str(video.get("creator_id") or ""),
|
||||
"nickname": str(video.get("nickname") or ""),
|
||||
"fans": video.get("creator_fans"),
|
||||
"total_favorited": video.get("creator_total_favorited"),
|
||||
"works": video.get("creator_works"),
|
||||
"following": video.get("creator_following"),
|
||||
}
|
||||
|
||||
|
||||
async def _creator_profile(
|
||||
sec_user_id: str,
|
||||
videos: Sequence[Dict[str, Any]],
|
||||
|
||||
Reference in New Issue
Block a user