Skip to content

Commit

Permalink
fix(小红书-动态): 由于接口不再返回note_id, 改用动态标题判断 #23
Browse files Browse the repository at this point in the history
  • Loading branch information
nfe-w committed Jun 26, 2024
1 parent 4fee86a commit a8aceba
Showing 1 changed file with 16 additions and 21 deletions.
37 changes: 16 additions & 21 deletions query_task/query_xhs.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,38 +69,33 @@ def query_dynamic(self, profile_id=None):
return

note = notes[0]
note_id = note["id"]
note_title = note["noteCard"]["displayTitle"]

if self.dynamic_dict.get(profile_id, None) is None:
self.dynamic_dict[profile_id] = deque(maxlen=self.len_of_deque)
for index in range(self.len_of_deque):
if index < len(notes):
self.dynamic_dict[profile_id].appendleft(notes[index]["id"])
self.dynamic_dict[profile_id].appendleft(notes[index]["noteCard"]["displayTitle"])
log.info(f"【小红书-查询动态状态-{self.name}】【{user_name}】动态初始化:{self.dynamic_dict[profile_id]}")
return

if note_id not in self.dynamic_dict[profile_id]:
previous_note_id = self.dynamic_dict[profile_id].pop()
self.dynamic_dict[profile_id].append(previous_note_id)
log.info(f"【小红书-查询动态状态-{self.name}】【{user_name}上一条动态id[{previous_note_id}],本条动态id[{note_id}]")
self.dynamic_dict[profile_id].append(note_id)
if note_title not in self.dynamic_dict[profile_id]:
previous_note_title = self.dynamic_dict[profile_id].pop()
self.dynamic_dict[profile_id].append(previous_note_title)
log.info(f"【小红书-查询动态状态-{self.name}】【{user_name}上一条动态标题[{previous_note_title}],本条动态标题[{note_title}]")
self.dynamic_dict[profile_id].append(note_title)
log.debug(self.dynamic_dict[profile_id])

note_detail_info = self.get_note_detail(note_id)
if note_detail_info is None:
log.error(f"【小红书-查询动态状态-{self.name}】获取不到笔记明细,不推送,note_id:{note_id}")
return
note_title = note_detail_info["title"]
note_desc = note_detail_info["desc"]
note_time_ts = note_detail_info["time"]
dynamic_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(note_time_ts / 1000))
note_title = note_title
note_desc = ''
dynamic_time = '无法获取内容,请打开小红书查看详情'

note_card = note["noteCard"]
content = f"【{note_title}{note_desc}"
pic_url = note_card["cover"]["infoList"][-1]["url"]
jump_url = f"https://www.xiaohongshu.com/explore/{note_card['noteId']}"
jump_url = f"https://www.xiaohongshu.com/user/profile/{profile_id}"
log.info(f"【小红书-查询动态状态-{self.name}】【{user_name}】动态有更新,准备推送:{content[:30]}")
self.push_for_xhs_dynamic(user_name, note_id, content, pic_url, jump_url, dynamic_time, dynamic_raw_data=note)
self.push_for_xhs_dynamic(user_name, note_title, content, pic_url, jump_url, dynamic_time, dynamic_raw_data=note)

def get_note_detail(self, note_id=None):
if note_id is None:
Expand Down Expand Up @@ -147,19 +142,19 @@ def get_headers():
"upgrade-insecure-requests": "1"
}

def push_for_xhs_dynamic(self, username=None, note_id=None, content=None, pic_url=None, jump_url=None, dynamic_time=None, dynamic_raw_data=None):
def push_for_xhs_dynamic(self, username=None, note_title=None, content=None, pic_url=None, jump_url=None, dynamic_time=None, dynamic_raw_data=None):
"""
小红书动态提醒推送
:param username: 博主名
:param note_id: 笔记id
:param note_title: 笔记标题
:param content: 动态内容
:param pic_url: 图片地址
:param jump_url: 跳转地址
:param dynamic_time: 动态发送时间
:param dynamic_raw_data: 动态原始数据
"""
if username is None or note_id is None or content is None:
log.error(f"【小红书-动态提醒推送-{self.name}】缺少参数,username:[{username}],note_id:[{note_id}],content:[{content[:30]}]")
if username is None or note_title is None or content is None:
log.error(f"【小红书-动态提醒推送-{self.name}】缺少参数,username:[{username}],note_title:[{note_title}],content:[{content[:30]}]")
return
title = f"【小红书】【{username}】发动态了"
content = f"{content[:100] + (content[100:] and '...')}[{dynamic_time}]"
Expand Down

0 comments on commit a8aceba

Please sign in to comment.