""" 评论管理 """ # 保存回复视频评论的用户昵称 # {"视频名称+发布日期":{"评论用户的昵称":{"评论内容集合"}}} import re import comment_util __reply_video_comment_user_name_dict = {} def add_reply_record(video_name, video_date, comment_nick_name, comment_content): """ 添加评论内容 :param video_name: :param video_date: :param comment_nick_name: :return: """ k = f"{video_name}{video_date}" if k not in __reply_video_comment_user_name_dict: __reply_video_comment_user_name_dict[k] = {} if comment_nick_name not in __reply_video_comment_user_name_dict[k]: __reply_video_comment_user_name_dict[k][comment_nick_name] = set() __reply_video_comment_user_name_dict[k][comment_nick_name].add(comment_content) def get_replay_content(video_info, comment_nick_name, comment_content): """ 获取回复内容 :param video_info:(视频名称, 日期, 评论次数, 视频标题) :param comment_nick_name:评论昵称 :param comment_content:评论内容 :return: """ video_name, video_date, video_title = video_info[0], video_info[1], video_info[3] k = f"{video_name}{video_date}" if k not in __reply_video_comment_user_name_dict: __reply_video_comment_user_name_dict[k] = {} if __reply_video_comment_user_name_dict[k].get(comment_nick_name): # 评论过了就不评论了 return None # 获取评论的正则表达式 comment_templates = comment_util.get_comment_templates() if not comment_templates: return None if not comment_content: return None # 替换评论内容中的img comment_content = comment_util.replace_img_with_alt(comment_content) for r in comment_templates: is_match = False if r[0].find("【视频标题】") >= 0: if comment_content.find(video_title)>=0: is_match = True elif re.match(r[0], comment_content): is_match = True if is_match: # 能够匹配到正则表达式 result = comment_util.load_content(r[1], comment_nick_name, comment_content) if result: return result return None def is_need_click_like(video_name, video_date, comment_nick_name, comment_content): """ 是否需要点赞 :param video_name: :param video_date: :param comment_nick_name: :param comment_content: :return: """ like_conditions = comment_util.get_like_conditions() if not like_conditions: return False # 替换评论内容中的img comment_content = comment_util.replace_img_with_alt(comment_content) for r in like_conditions: if re.match(r, comment_content): # 能够匹配到正则表达式 return True return False