增加更多控件类型和新增获取指定聊天窗口的聊天记录,并按时间信息分组的功能#70
Merged
LTEnjoy merged 3 commits intoLTEnjoy:mainfrom Sep 17, 2024
Merged
Conversation
LTEnjoy
reviewed
Sep 17, 2024
Owner
There was a problem hiding this comment.
感谢你的贡献!我已经检查运行过代码了,没有什么大问题。 但是在按照时间分组的函数里面,有一个逻辑问题是你把current_group初始化为空列表[]。这会导致如果搜索到的第一批聊天记录里的第一条不是时间消息,程序也会把这条消息作为一个新的分组的第一条消息。实际上是不应该的,因为所有分组的第一条消息都应该是时间消息。我对程序做了一下改动,你可以参考检查一下:
def get_dialogs_by_time_blocks(self, name: str, n_time_blocks: int, search_user: bool = True) -> List[List]:
"""
获取指定聊天窗口的聊天记录,并按时间信息分组。
Args:
name: 聊天窗口的姓名
n_time_blocks: 获取的时间分块数量
search_user: 是否需要搜索用户
Return:
groups: 聊天记录列表,每个元素为一个时间分块内的消息列表
"""
n_msg = n_time_blocks * 5
prev_dialogs = None
groups = []
while True:
dialogs = self.get_dialogs(name, n_msg, search_user)
# 如果获取的dialogs和之前一样,说明没有更多消息了,退出循环
if prev_dialogs == dialogs:
break
# 分组逻辑调整:处理顺序改为从最新消息到最早消息
groups = []
current_group = None
# 遍历所有消息,按照时间信息分组
for msg in dialogs:
# 遇见时间信息则新建一个分组
if msg[0] == '时间信息':
# 将上一个分组加入到groups中
if current_group is not None:
groups.append(current_group)
# 初始化新的分组
current_group = [msg]
elif current_group is not None:
current_group.append(msg)
# 将最后一个分组加入到groups中
if current_group is not None:
groups.append(current_group)
# 获取n_time_blocks个时间块,取groups的最后n_time_blocks个元素
if len(groups) >= n_time_blocks:
groups = groups[-n_time_blocks:]
break
else:
prev_dialogs = dialogs
n_msg *= 2
search_user = False # 后续不需要再次搜索用户
return groups
Contributor
Author
|
😯确实是我疏忽了,感谢指出错误 我按照你的代码修改了这部分逻辑,麻烦你再Review一下 |
LTEnjoy
approved these changes
Sep 17, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
增加更多控件类型
我获取聊天记录时,发现有两个控件无法识别
“以下是新信息”
这个控件在微信里显示的是“以下是新信息”,但在list_item_control.Name里却是"以下为新消息",有点怪
增加了新的条件:
“英文版的对方打开红包”
之前把"Red packet"加入了判断条件,但没想到微信的命名规范没统一,这次的是"Red Packet"(Packet的“P”是大写)
所以应该把控件的字母全部都转化为小写再比较
elif "红包" in list_item_control.Name or "red packet" in list_item_control.Name.lower():新增获取指定聊天窗口的聊天记录,并按时间信息分组的功能
在处理聊天记录时,我发现更多时候我们并不知道需要获取多少条聊天记录,而是需要获取一个时间节点的消息,如昨天的消息
所以我新增了一个方法
get_dialogs_by_time_blocks,会以时间块来分区聊天记录,返回嵌套列表,元素是一串以时间消息分割的消息列表,例如:这样处理聊天记录时更方便了