feat(matrix): 「第一条视频」改成主页最新一条,即使不在监控目标里
之前取的是本任务已有作品里**最早**的那条 —— 既不是主页上看到的第一条, 也只看得到被监控的那批链接。现在采集时对每个博主额外问一次作品列表 (倒序,只要第一条),把它的发布时间落进账号快照;矩阵优先用它,没问到 时退回库里最新的一条作品。 - 作品模式:每个博主每轮一次请求,同轮内去重;连接超时重试一次。 - 博主模式:本来就在拉作品列表,直接用其中的最新时间。 - 新列 monitor_creator_stat.latest_published_at(毫秒,可空)。
This commit is contained in:
+31
-8
@@ -1580,7 +1580,7 @@ async def daily_tag_matrix(
|
||||
{"dates": ["2026-10-21", ...], # 新到旧
|
||||
"creators": [{"hash": ..., "name": ..., "fans": 1200,
|
||||
"total_favorited": 83000,
|
||||
"first_published_at": 1780000000000}], # 按昵称排序
|
||||
"latest_published_at": 1780000000000}], # 按昵称排序
|
||||
"cells": {"2026-10-21": {"<hash>": {
|
||||
"count": 2, "tags": ["大字报", "养号"],
|
||||
"likes": 120, "comments": 8, "collected": 30, "shares": 4,
|
||||
@@ -1704,6 +1704,7 @@ async def daily_tag_matrix(
|
||||
MonitorCreatorStat.captured_at,
|
||||
MonitorCreatorStat.fans,
|
||||
MonitorCreatorStat.total_favorited,
|
||||
MonitorCreatorStat.latest_published_at,
|
||||
).where(
|
||||
MonitorCreatorStat.task_id.in_(task_ids),
|
||||
MonitorCreatorStat.creator_hash != "",
|
||||
@@ -1716,6 +1717,8 @@ async def daily_tag_matrix(
|
||||
latest_fans: Dict[str, tuple] = {}
|
||||
# 主页上的「获赞总数」,和粉丝数一样取最近一次读到的值。
|
||||
latest_likes: Dict[str, tuple] = {}
|
||||
# 主页第一条(最新)视频的发布时间。采集时问过主页,这条可能不在监控目标里。
|
||||
latest_video: Dict[str, tuple] = {}
|
||||
for stat in stat_rows:
|
||||
if stat.fans is not None:
|
||||
current_fans = latest_fans.get(stat.creator_hash)
|
||||
@@ -1728,6 +1731,13 @@ async def daily_tag_matrix(
|
||||
stat.total_favorited,
|
||||
stat.captured_at,
|
||||
)
|
||||
if stat.latest_published_at is not None:
|
||||
current_video = latest_video.get(stat.creator_hash)
|
||||
if current_video is None or stat.captured_at > current_video[1]:
|
||||
latest_video[stat.creator_hash] = (
|
||||
stat.latest_published_at,
|
||||
stat.captured_at,
|
||||
)
|
||||
# **空昵称不算名字。** 资料接口偶尔会回一个空对象(昵称、sec_uid、粉丝、
|
||||
# 作品数全空),如果把这一轮当最新快照,就会用一个空字符串把之前的好名字
|
||||
# 盖掉,界面上变成「未知(hash)」。实测线上有两个号就是这么丢的名字。
|
||||
@@ -1814,11 +1824,11 @@ async def daily_tag_matrix(
|
||||
# 作品是按发布时间倒序取回来的,明细按时间正序更好读(1、2、3…)。
|
||||
bucket["details"].reverse()
|
||||
|
||||
# 博主的**第一条视频**发布时间。查全库,不受上面 days 窗口的限制 —— 一个号最早的
|
||||
# 作品很可能在窗口之外,而「这个号做了多久」看的就是它。
|
||||
first_rows = (
|
||||
# 兜底:库里这个博主**已有作品里最新的**发布时间。首选是采集时从主页拿到的
|
||||
# 「第一条视频」(它可能根本不在监控目标里),主页那次没问到时才用它。
|
||||
tracked_rows = (
|
||||
await session.execute(
|
||||
select(MonitorNote.creator_hash, func.min(MonitorNote.published_at))
|
||||
select(MonitorNote.creator_hash, func.max(MonitorNote.published_at))
|
||||
.where(
|
||||
MonitorNote.task_id.in_(task_ids),
|
||||
MonitorNote.published_at.is_not(None),
|
||||
@@ -1827,8 +1837,10 @@ async def daily_tag_matrix(
|
||||
.group_by(MonitorNote.creator_hash)
|
||||
)
|
||||
).all()
|
||||
first_published: Dict[str, int] = {
|
||||
creator_hash: first_at for creator_hash, first_at in first_rows if first_at
|
||||
latest_tracked: Dict[str, int] = {
|
||||
creator_hash: latest_at
|
||||
for creator_hash, latest_at in tracked_rows
|
||||
if latest_at
|
||||
}
|
||||
|
||||
creators = [
|
||||
@@ -1839,7 +1851,18 @@ async def daily_tag_matrix(
|
||||
# 前端据此不画那个数字,而不是显示 0。
|
||||
"fans": latest_fans.get(hash_, (None, 0))[0],
|
||||
"total_favorited": latest_likes.get(hash_, (None, 0))[0],
|
||||
"first_published_at": first_published.get(hash_),
|
||||
# 两个来源取较新的一个:主页数据可能比库里的作品旧(快照是上一轮的)。
|
||||
"latest_published_at": max(
|
||||
[
|
||||
value
|
||||
for value in (
|
||||
latest_video.get(hash_, (None, 0))[0],
|
||||
latest_tracked.get(hash_),
|
||||
)
|
||||
if value
|
||||
],
|
||||
default=None,
|
||||
),
|
||||
}
|
||||
for hash_, name in known.items()
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user