admin
2025-03-28 3e9ea4f148c406cc5ffec59f2eac433c219a5466
初始化导入
2个文件已修改
20 ■■■■ 已修改文件
comment.py 15 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
main.py 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
comment.py
@@ -9,6 +9,8 @@
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import setting
class CommentManager:
@@ -29,7 +31,8 @@
        comment_template_str = ""
        # 将中文替换为正则表达式支持的unicode编码
        comment_template_str = comment_template_str.encode('unicode_escape').decode("utf-8")
        self.comment_templates = [(x.split("#")[0], x.split("#")[1]) if x.find("#")>=0 for x in comment_template_str.split("\n")]
        self.comment_templates = [(x.split("#")[0], x.split("#")[1]) for x in comment_template_str.split("\n") if
                                  x.find("#") >= 0]
        self.driver = None
    def __init(self):
@@ -78,12 +81,15 @@
        :param comment_element:
        :return:
        """
        def get_reply_comment(nick_name, content):
            if not setting.is_reply_comment():
                return None
            # 内容是否符合标准
            for t in self.comment_templates:
                if re.match(t[0], content):
                    # 满足内容
                    retrun t[1].replace("[昵称]",nick_name)
                    return t[1].replace("[昵称]", nick_name)
        comment_pattern = re.compile(r'[\u4e00-\u9fa5]+')
        comment_content = re.sub("<img.*?>", "", comment_content)
@@ -104,8 +110,8 @@
        comment_actions[1].click()
        wait = WebDriverWait(self.driver, 5)  # 最多等待10秒
        element = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "comment-create-content")))
        replay_content = get_reply_comment(, comment_element)
        # TODO 昵称
        replay_content = get_reply_comment("昵称", comment_element)
        if not replay_content:
            # 不需要评论
            return
@@ -117,7 +123,6 @@
        self.driver.find_element(By.CLASS_NAME,
                            "comment-create-content").find_element(By.XPATH, "div[3]/div[2]").click()
        time.sleep(2)
    def __click_like_all(self, driver, start_index=0):
        scroll_list = driver.find_element(By.CLASS_NAME, "feed-comment__wrp")
main.py
@@ -46,6 +46,9 @@
            open_file_dialog.Destroy()
        def start_comment(event):
            if self.comment_manager:
                self.comment_manager.close()
            self.comment_manager = CommentManager()
            threading.Thread(target=lambda: self.comment_manager.start_process_comment(), daemon=True).start()
        def on_save(event):
@@ -74,7 +77,6 @@
        self.btn_save.Bind(wx.EVT_BUTTON, on_save)
    def __init(self):
        self.comment_manager = CommentManager()
        self.cb_like.SetValue(setting.is_click_like())
        self.cb_comment.SetValue(setting.is_reply_comment())
        self.text_comments.SetValue(setting.get_comment_templates())
@@ -143,6 +145,7 @@
    def OnFrameClose(self, evt):
        print("页面关闭")
        if self.comment_manager:
        self.comment_manager.close()
        evt.Skip()