refactor: 教学版移除全平台用户个人信息采集与持久化

- 用户 ID 转为匿名 creator_hash,昵称中间脱敏,IP/头像/主页/签名/性别不再采集
- 覆盖 xhs/weibo/bilibili/douyin/kuaishou/tieba/zhihu 7 个平台
- 删除 7 张 creator 档案 ORM 表,15 张内容/评论表新增 creator_hash 列
- B 站禁用粉丝/关注/联系人列表抓取
- 新增 tools/user_hash.py 与 4 个平台的 mock+SQLite 端到端测试

测试: pytest tests/test_no_user_info.py tests/test_weibo_no_user_info.py tests/test_douyin_no_user_info.py tests/test_kuaishou_no_user_info.py (21 passed)
This commit is contained in:
程序员阿江(Relakkes)
2026-07-01 13:09:55 +08:00
parent 8b4d8fcffa
commit 9f4f8bf768
26 changed files with 1426 additions and 822 deletions
+9 -25
View File
@@ -26,6 +26,7 @@ from typing import List
import config
from var import source_keyword_var
from tools.user_hash import anonymize_user_id, mask_nickname
from ._store_impl import *
@@ -63,9 +64,8 @@ async def update_kuaishou_video(video_item: Dict):
"title": photo_info.get("caption", "")[:500],
"desc": photo_info.get("caption", "")[:500],
"create_time": photo_info.get("timestamp"),
"user_id": user_info.get("id"),
"nickname": user_info.get("name"),
"avatar": user_info.get("headerUrl", ""),
"creator_hash": anonymize_user_id(user_info.get("id")), # 创作者匿名哈希(不存原始 user_id)
"nickname": mask_nickname(user_info.get("name")), # 用户昵称(已脱敏)
"liked_count": str(photo_info.get("realLikeCount")),
"viewd_count": str(photo_info.get("viewCount")),
"last_modify_ts": utils.get_current_timestamp(),
@@ -97,11 +97,10 @@ async def update_ks_video_comment(video_id: str, comment_item: Dict):
"create_time": comment_item.get("timestamp"),
"video_id": video_id,
"content": comment_item.get("content"),
# V2: author_id, Old: authorId
"user_id": comment_item.get("author_id") or comment_item.get("authorId"),
# V2: author_name, Old: authorName
"nickname": comment_item.get("author_name") or comment_item.get("authorName"),
"avatar": comment_item.get("headurl"),
# 创作者匿名哈希(不存原始 user_id):V2: author_id, Old: authorId
"creator_hash": anonymize_user_id(comment_item.get("author_id") or comment_item.get("authorId")),
# 用户昵称(已脱敏):V2: author_name, Old: authorName
"nickname": mask_nickname(comment_item.get("author_name") or comment_item.get("authorName")),
# V2: commentCount, Old: subCommentCount
"sub_comment_count": str(comment_item.get("commentCount") or comment_item.get("subCommentCount", 0)),
"last_modify_ts": utils.get_current_timestamp(),
@@ -111,20 +110,5 @@ async def update_ks_video_comment(video_id: str, comment_item: Dict):
await KuaishouStoreFactory.create_store().store_comment(comment_item=save_comment_item)
async def save_creator(user_id: str, creator: Dict):
ownerCount = creator.get('ownerCount', {})
profile = creator.get('profile', {})
local_db_item = {
'user_id': user_id,
'nickname': profile.get('user_name'),
'gender': 'Female' if profile.get('gender') == "F" else 'Male',
'avatar': profile.get('headurl'),
'desc': profile.get('user_text'),
'ip_location': "",
'follows': ownerCount.get("follow"),
'fans': ownerCount.get("fan"),
'interaction': ownerCount.get("photo_public"),
"last_modify_ts": utils.get_current_timestamp(),
}
utils.logger.info(f"[store.kuaishou.save_creator] creator:{local_db_item}")
await KuaishouStoreFactory.create_store().store_creator(local_db_item)
# 教学版:创作者个人资料(昵称/性别/头像/签名/IP/粉丝数等)不再落库,防骚扰。
return
+2 -15
View File
@@ -228,21 +228,8 @@ class KuaishouMongoStoreImplement(AbstractStore):
utils.logger.info(f"[KuaishouMongoStoreImplement.store_comment] Saved comment {comment_id} to MongoDB")
async def store_creator(self, creator_item: Dict):
"""
Store creator information to MongoDB
Args:
creator_item: Creator data
"""
user_id = creator_item.get("user_id")
if not user_id:
return
await self.mongo_store.save_or_update(
collection_suffix="creators",
query={"user_id": user_id},
data=creator_item
)
utils.logger.info(f"[KuaishouMongoStoreImplement.store_creator] Saved creator {user_id} to MongoDB")
# 教学版:创作者个人资料不再落库
pass
class KuaishouExcelStoreImplement: