chore: add xhs field comment for issue #526

This commit is contained in:
Relakkes 2024-12-26 18:28:23 +08:00
parent 29ab6feded
commit 79bf9fc05d

View File

@ -87,27 +87,27 @@ async def update_xhs_note(note_item: Dict):
video_url = ','.join(get_video_url_arr(note_item)) video_url = ','.join(get_video_url_arr(note_item))
local_db_item = { local_db_item = {
"note_id": note_item.get("note_id"), "note_id": note_item.get("note_id"), # 帖子id
"type": note_item.get("type"), "type": note_item.get("type"), # 帖子类型
"title": note_item.get("title") or note_item.get("desc", "")[:255], "title": note_item.get("title") or note_item.get("desc", "")[:255], # 帖子标题
"desc": note_item.get("desc", ""), "desc": note_item.get("desc", ""), # 帖子描述
"video_url": video_url, "video_url": video_url, # 帖子视频url
"time": note_item.get("time"), "time": note_item.get("time"), # 帖子发布时间
"last_update_time": note_item.get("last_update_time", 0), "last_update_time": note_item.get("last_update_time", 0), # 帖子最后更新时间
"user_id": user_info.get("user_id"), "user_id": user_info.get("user_id"), # 用户id
"nickname": user_info.get("nickname"), "nickname": user_info.get("nickname"), # 用户昵称
"avatar": user_info.get("avatar"), "avatar": user_info.get("avatar"), # 用户头像
"liked_count": interact_info.get("liked_count"), "liked_count": interact_info.get("liked_count"), # 点赞数
"collected_count": interact_info.get("collected_count"), "collected_count": interact_info.get("collected_count"), # 收藏数
"comment_count": interact_info.get("comment_count"), "comment_count": interact_info.get("comment_count"), # 评论数
"share_count": interact_info.get("share_count"), "share_count": interact_info.get("share_count"), # 分享数
"ip_location": note_item.get("ip_location", ""), "ip_location": note_item.get("ip_location", ""), # ip地址
"image_list": ','.join([img.get('url', '') for img in image_list]), "image_list": ','.join([img.get('url', '') for img in image_list]), # 图片url
"tag_list": ','.join([tag.get('name', '') for tag in tag_list if tag.get('type') == 'topic']), "tag_list": ','.join([tag.get('name', '') for tag in tag_list if tag.get('type') == 'topic']), # 标签
"last_modify_ts": utils.get_current_timestamp(), "last_modify_ts": utils.get_current_timestamp(), # 最后更新时间戳MediaCrawler程序生成的主要用途在db存储的时候记录一条记录最新更新时间
"note_url": f"https://www.xiaohongshu.com/explore/{note_id}?xsec_token={note_item.get('xsec_token')}&xsec_source=pc_search", "note_url": f"https://www.xiaohongshu.com/explore/{note_id}?xsec_token={note_item.get('xsec_token')}&xsec_source=pc_search", # 帖子url
"source_keyword": source_keyword_var.get(), "source_keyword": source_keyword_var.get(), # 搜索关键词
"xsec_token": note_item.get("xsec_token"), "xsec_token": note_item.get("xsec_token"), # xsec_token
} }
utils.logger.info(f"[store.xhs.update_xhs_note] xhs note: {local_db_item}") utils.logger.info(f"[store.xhs.update_xhs_note] xhs note: {local_db_item}")
await XhsStoreFactory.create_store().store_content(local_db_item) await XhsStoreFactory.create_store().store_content(local_db_item)
@ -144,18 +144,18 @@ async def update_xhs_note_comment(note_id: str, comment_item: Dict):
comment_pictures = [item.get("url_default", "") for item in comment_item.get("pictures", [])] comment_pictures = [item.get("url_default", "") for item in comment_item.get("pictures", [])]
target_comment = comment_item.get("target_comment", {}) target_comment = comment_item.get("target_comment", {})
local_db_item = { local_db_item = {
"comment_id": comment_id, "comment_id": comment_id, # 评论id
"create_time": comment_item.get("create_time"), "create_time": comment_item.get("create_time"), # 评论时间
"ip_location": comment_item.get("ip_location"), "ip_location": comment_item.get("ip_location"), # ip地址
"note_id": note_id, "note_id": note_id, # 帖子id
"content": comment_item.get("content"), "content": comment_item.get("content"), # 评论内容
"user_id": user_info.get("user_id"), "user_id": user_info.get("user_id"), # 用户id
"nickname": user_info.get("nickname"), "nickname": user_info.get("nickname"), # 用户昵称
"avatar": user_info.get("image"), "avatar": user_info.get("image"), # 用户头像
"sub_comment_count": comment_item.get("sub_comment_count", 0), "sub_comment_count": comment_item.get("sub_comment_count", 0), # 子评论数
"pictures": ",".join(comment_pictures), "pictures": ",".join(comment_pictures), # 评论图片
"parent_comment_id": target_comment.get("id", 0), "parent_comment_id": target_comment.get("id", 0), # 父评论id
"last_modify_ts": utils.get_current_timestamp(), "last_modify_ts": utils.get_current_timestamp(), # 最后更新时间戳MediaCrawler程序生成的主要用途在db存储的时候记录一条记录最新更新时间
"like_count": comment_item.get("like_count", 0), "like_count": comment_item.get("like_count", 0),
} }
utils.logger.info(f"[store.xhs.update_xhs_note_comment] xhs note comment:{local_db_item}") utils.logger.info(f"[store.xhs.update_xhs_note_comment] xhs note comment:{local_db_item}")
@ -186,18 +186,18 @@ async def save_creator(user_id: str, creator: Dict):
interaction = i.get('count') interaction = i.get('count')
local_db_item = { local_db_item = {
'user_id': user_id, 'user_id': user_id, # 用户id
'nickname': user_info.get('nickname'), 'nickname': user_info.get('nickname'), # 昵称
'gender': '' if user_info.get('gender') == 1 else '', 'gender': '' if user_info.get('gender') == 1 else '', # 性别
'avatar': user_info.get('images'), 'avatar': user_info.get('images'), # 头像
'desc': user_info.get('desc'), 'desc': user_info.get('desc'), # 个人描述
'ip_location': user_info.get('ipLocation'), 'ip_location': user_info.get('ipLocation'), # ip地址
'follows': follows, 'follows': follows, # 关注数
'fans': fans, 'fans': fans, # 粉丝数
'interaction': interaction, 'interaction': interaction, # 互动数
'tag_list': json.dumps({tag.get('tagType'): tag.get('name') for tag in creator.get('tags')}, 'tag_list': json.dumps({tag.get('tagType'): tag.get('name') for tag in creator.get('tags')},
ensure_ascii=False), ensure_ascii=False), # 标签
"last_modify_ts": utils.get_current_timestamp(), "last_modify_ts": utils.get_current_timestamp(), # 最后更新时间戳MediaCrawler程序生成的主要用途在db存储的时候记录一条记录最新更新时间
} }
utils.logger.info(f"[store.xhs.save_creator] creator:{local_db_item}") utils.logger.info(f"[store.xhs.save_creator] creator:{local_db_item}")
await XhsStoreFactory.create_store().store_creator(local_db_item) await XhsStoreFactory.create_store().store_creator(local_db_item)