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:
@@ -214,6 +214,63 @@ class TestNoteMode:
|
||||
assert any("222" in error for error in result["errors"])
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_creator_stats_come_from_the_detail_itself(self, monkeypatch, tmp_path):
|
||||
"""作品模式不拉博主资料,粉丝数只能从详情返回的 author 里拿。
|
||||
|
||||
不带出来的话,超级编导导入的任务里每个博主都没有粉丝数 —— 而运营要看的就是
|
||||
「这批号多大」。详情里作者那段是白拿的,不需要多发一次请求。
|
||||
"""
|
||||
|
||||
async def fake_detail(aweme_id, *, cookie="", identity=None):
|
||||
record = _video(aweme_id)
|
||||
record.update(
|
||||
{
|
||||
"creator_id": "MS4wLjABAAAAsecuid",
|
||||
"creator_fans": 1444,
|
||||
"creator_total_favorited": 9751,
|
||||
"creator_works": None,
|
||||
"creator_following": 0,
|
||||
}
|
||||
)
|
||||
return record
|
||||
|
||||
monkeypatch.setattr(douyin_api, "video_detail", fake_detail)
|
||||
|
||||
result = await _collect(
|
||||
tmp_path, mode="note", want_comments=False, targets=[_Target("111")]
|
||||
)
|
||||
|
||||
profiles = _read(
|
||||
list((tmp_path / "douyin" / "jsonl").glob("*_profile_*.jsonl"))[0]
|
||||
)
|
||||
assert result["notes"] == 1
|
||||
assert len(profiles) == 1
|
||||
assert profiles[0]["fans"] == 1444
|
||||
assert profiles[0]["total_favorited"] == 9751
|
||||
assert profiles[0]["creator_id"] == "MS4wLjABAAAAsecuid"
|
||||
# 详情里没有作品总数,留 None 而不是 0。
|
||||
assert profiles[0]["works"] is None
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_no_stats_means_no_profile_row(self, monkeypatch, tmp_path):
|
||||
"""精简版 author(字段全缺)不该写一条全 NULL 的快照。"""
|
||||
|
||||
async def fake_detail(aweme_id, *, cookie="", identity=None):
|
||||
return _video(aweme_id)
|
||||
|
||||
monkeypatch.setattr(douyin_api, "video_detail", fake_detail)
|
||||
|
||||
await _collect(
|
||||
tmp_path, mode="note", want_comments=False, targets=[_Target("111")]
|
||||
)
|
||||
|
||||
profiles = _read(
|
||||
list((tmp_path / "douyin" / "jsonl").glob("*_profile_*.jsonl"))[0]
|
||||
)
|
||||
assert profiles == []
|
||||
|
||||
|
||||
class TestDegradation:
|
||||
"""作品列表被挡时的行为 —— 决定了这个功能今天有没有用。"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user