From 4603536999de113969dd7164f3a04dcde9083480 Mon Sep 17 00:00:00 2001
From: admin <weikou2014>
Date: 星期一, 31 三月 2025 13:19:42 +0800
Subject: [PATCH] 初始化导入

---
 comment_manager.py |   81 ++++++++
 video_manager.py   |   47 ++++
 comment_util.py    |  125 ++++++++++++
 setting.py         |   33 +++
 tool.py            |   15 +
 res/setting.conf   |    7 
 main.py            |  134 +++++++++++--
 res/comment.txt    |    4 
 comment.py         |  135 +++++++++---
 9 files changed, 520 insertions(+), 61 deletions(-)

diff --git a/comment.py b/comment.py
index c0e93a2..cdbd18c 100644
--- a/comment.py
+++ b/comment.py
@@ -1,4 +1,3 @@
-import re
 import threading
 import time
 
@@ -9,7 +8,9 @@
 from selenium.webdriver.support.wait import WebDriverWait
 from selenium.webdriver.support import expected_conditions as EC
 
+import comment_manager
 import setting
+from video_manager import VideoManger
 
 
 class CommentManager:
@@ -50,20 +51,19 @@
         # 绛夊埌宸︿晶鑿滃崟鍑虹幇鍚庢墠鑳芥墽琛屽悗缁搷浣�
         wait = WebDriverWait(self.driver, 100)  # 鏈�澶氱瓑寰�10绉�
         element = wait.until(EC.visibility_of_element_located((By.ID, "side-bar")))
-        threading.Thread(target=lambda: self.click_like(self.driver), daemon=True).start()
+        threading.Thread(target=lambda: self.process_videos(self.driver), daemon=True).start()
 
-    def __process_like(self, comment_content, comment_element):
+    def __process_like(self, video_name, video_date, comment_element):
         """
         澶勭悊鍗曟潯璇勮鐨勮禐
         :param comment_content:
         :param comment_element:
         :return:
         """
-        comment_pattern = re.compile(r'[\u4e00-\u9fa5]+')
-        comment_content = re.sub("<img.*?>", "", comment_content)
-        if not comment_pattern.search(comment_content):
-            # 绗﹀悎鏍囧噯鐨勮瘎璁�
+        user_name, comment_content, comment_time = self.__parse_comment_info(comment_element)
+        if not comment_manager.is_need_click_like(video_name, video_date, user_name, comment_content):
             return
+
         comment_actions = comment_element.find_element(By.CLASS_NAME, "action-list").find_elements(By.CLASS_NAME,
                                                                                                    "action-item")
         classes: str = comment_actions[0].find_element(By.TAG_NAME, "svg").get_attribute("class")
@@ -72,50 +72,73 @@
             return
         like = comment_element.find_element(By.CLASS_NAME, "like-action")
         like.click()
-        self.driver.implicitly_wait(2)
+        # self.driver.implicitly_wait(2)
+        time.sleep(2)
 
-    def __process_reply(self, comment_content, comment_element):
+    def __parse_comment_info(self, comment_element):
         """
-        澶勭悊鍗曟潯璇勮鐨勫洖澶�
-        :param comment_content:
+        瑙f瀽璇勮淇℃伅
         :param comment_element:
-        :return:
+        :return:(璇勮浜�,璇勮鍐呭,璇勮鏃堕棿)
+        """
+        user_name = comment_element.find_element(By.CLASS_NAME, "comment-user-name").get_attribute("innerHTML")
+        comment_time = comment_element.find_element(By.CLASS_NAME, "comment-time").get_attribute("innerHTML")
+        comment_content = comment_element.find_element(By.CLASS_NAME, "comment-content").get_attribute("innerHTML")
+        return user_name, comment_content, comment_time
+
+    def __parse_video_info(self, video_element):
+        """
+        瑙f瀽瑙嗛淇℃伅
+        :param comment_element:
+        :return:(瑙嗛鍚嶇О,瑙嗛鏃堕棿,璇勮鏁伴噺)
+        """
+        video_time = video_element.find_element(By.CLASS_NAME, "feed-time").get_attribute("innerHTML")
+        comment_count = video_element.find_element(By.CLASS_NAME, "feed-comment-total").find_element(By.XPATH,
+                                                                                                     "./span[2]").get_attribute(
+            "innerHTML")
+        video_name = video_element.find_element(By.CLASS_NAME, "comment-content").get_attribute("innerHTML")
+        return video_name, video_time, comment_count
+
+    def __process_reply(self, video_name, video_date, comment_element):
+        """
+        澶勭悊鍗曟潯璇勮鍥炲
+        :param video_name:
+        :param video_date:
+        :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):
-                    # 婊¤冻鍐呭
-                    return t[1].replace("[鏄电О]", nick_name)
+            return comment_manager.get_replay_content(video_name, video_date, nick_name, content)
 
-        comment_pattern = re.compile(r'[\u4e00-\u9fa5]+')
-        comment_content = re.sub("<img.*?>", "", comment_content)
-        if not comment_pattern.search(comment_content):
-            # 绗﹀悎鏍囧噯鐨勮瘎璁�
-            return
+        comment_user_name, comment_content, comment_time = self.__parse_comment_info(comment_element)
+
         try:
             comment_reply_list = comment_element.find_element(By.CLASS_NAME, "comment-reply-list")
             if comment_reply_list.find_element(By.XPATH, ".//div[normalize-space()='浣滆��']"):
                 print("宸茬粡鍥炲銆傘�傘�傘��")
-                return
+                return False
         except:
             print("杩樻病鍥炲銆傘�傘�傘��")
+
+        replay_content = get_reply_comment(comment_user_name, comment_element)
+        if not replay_content:
+            # 涓嶉渶瑕佽瘎璁�
+            print("涓嶉渶瑕佸洖澶嶃�傘�傘�傘��")
+            return True
+
+        # 闇�瑕佸洖澶�
 
         comment_actions = comment_element.find_element(By.CLASS_NAME, "action-list").find_elements(By.CLASS_NAME,
                                                                                                    "action-item")
         # 鐐瑰嚮璇勮
         comment_actions[1].click()
         wait = WebDriverWait(self.driver, 5)  # 鏈�澶氱瓑寰�10绉�
-        element = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "comment-create-content")))
-        # TODO 鏄电О
-        replay_content = get_reply_comment("鏄电О", comment_element)
-        if not replay_content:
-            # 涓嶉渶瑕佽瘎璁�
-            return
-
+        wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "comment-create-content")))
+        time.sleep(1)
         self.driver.find_element(By.CLASS_NAME,
                                  "comment-create-content").find_element(By.TAG_NAME,
                                                                         "textarea").send_keys(replay_content)
@@ -123,8 +146,16 @@
         self.driver.find_element(By.CLASS_NAME,
                                  "comment-create-content").find_element(By.XPATH, "div[3]/div[2]").click()
         time.sleep(2)
+        return False
 
-    def __click_like_all(self, driver, start_index=0):
+    def __process_comments(self, driver, start_index=0, video_info=None):
+        """
+
+        :param driver:
+        :param start_index:
+        :param video_info:(瑙嗛鍐呭, 瑙嗛鏃ユ湡, 璇勮娆℃暟)
+        :return:
+        """
         scroll_list = driver.find_element(By.CLASS_NAME, "feed-comment__wrp")
 
         loadmore = scroll_list.find_element(By.CLASS_NAME, "loadmore__dot")
@@ -137,34 +168,60 @@
         for index in range(start_index, len(comments)):
             comment = comments[index]
             # 璇勮鍐呭
-            comment_content = comment.find_element(By.CLASS_NAME, "comment-content").get_attribute("innerHTML")
+            user_name, comment_content, comment_time = self.__parse_comment_info(comment)
             if not comment_content:
                 continue
             print("=======璇勮鍐呭锛�", comment_content)
-            self.__process_reply(comment_content, comment)
-            self.__process_like(comment_content, comment)
+            need_like = self.__process_reply(video_info[0], video_info[1], comment)
+            if need_like:
+                print("闇�瑕佺偣璧�")
+                self.__process_like(video_info[0], video_info[1], comment)
+            else:
+                print("涓嶉渶瑕佺偣璧�")
         # 寰�涓嬫粦鍔�
         if has_more:
             driver.execute_script(
                 "var __comment_scroll = document.getElementsByClassName('feed-comment__wrp')[0]; __comment_scroll.scrollTop = __comment_scroll.scrollHeight;")
             print("寰�涓嬫粴鍔�")
             time.sleep(3)
-            self.__click_like_all(driver, start_index=len(comments))
+            self.__process_comments(driver, start_index=len(comments))
         else:
-            print("娌℃湁鏇村浜�")
+            print("娌℃湁鏇村璇勮浜�")
 
-    def click_like(self, driver: webdriver.Chrome):
+    def process_videos(self, driver: webdriver.Chrome, start_index=0):
         wait = WebDriverWait(driver, 100)  # 鏈�澶氱瓑寰�10绉�
-        element = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "feeds-container")))
+        scroll_list = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "feeds-container")))
         time.sleep(1)
         # 鏌ユ壘瑙嗛鍒楄〃
         videos_root = driver.find_element(By.CLASS_NAME, "feeds-container")
         videos = videos_root.find_elements(By.CLASS_NAME, "comment-feed-wrap")
-        for video in videos:
+        for i in range(start_index, len(videos)):
             # 閫夋嫨瑙嗛
+            video = videos[i]
+            # 瑙f瀽瑙嗛鍐呭
+            video_name, video_time, comment_count = self.__parse_video_info(video)
+            # 鍒ゆ柇鏄惁瑕佺偣鍑昏繘鍘�
+            if not VideoManger().is_need_click(video_name, video_time, comment_count):
+                continue
             video.click()
             driver.implicitly_wait(2)
-            self.__click_like_all(driver)
+            self.__process_comments(driver, video_info=(video_name, video_time, comment_count))
+            # 5s澶勭悊涓�涓棰�
+            time.sleep(5)
+
+        loadmore = scroll_list.find_element(By.CLASS_NAME, "loadmore__dot")
+        # 鑾峰彇鐖舵帶浠�
+        loadmore = loadmore.find_element(By.XPATH, "./..")
+        has_more = loadmore.value_of_css_property("display") == "none"
+        if has_more:
+            driver.execute_script(
+                "var __video_scroll = document.getElementsByClassName('feeds-container')[0]; __video_scroll.scrollTop = __video_scroll.scrollHeight;")
+            print("寰�涓嬫粴鍔�")
+            time.sleep(3)
+            self.process_videos(driver, start_index=len(videos))
+        else:
+            print("娌℃湁鏇村瑙嗛浜�")
+            VideoManger().add_video_infos([self.__parse_video_info(v) for v in videos])
 
     def close(self):
         if self.driver:
diff --git a/comment_manager.py b/comment_manager.py
new file mode 100644
index 0000000..4c72cd4
--- /dev/null
+++ b/comment_manager.py
@@ -0,0 +1,81 @@
+"""
+璇勮绠$悊
+"""
+# 淇濆瓨鍥炲瑙嗛璇勮鐨勭敤鎴锋樀绉�
+# {"瑙嗛鍚嶇О+鍙戝竷鏃ユ湡":{"璇勮鐢ㄦ埛鐨勬樀绉�":{"璇勮鍐呭闆嗗悎"}}}
+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_name, video_date, comment_nick_name, comment_content):
+    """
+    鑾峰彇鍥炲鍐呭
+    :param video_name:瑙嗛鍚嶇О
+    :param video_date:瑙嗛鏃ユ湡
+    :param comment_nick_name:璇勮鏄电О
+    :param comment_content:璇勮鍐呭
+    :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 __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:
+        if r.match(r[0], comment_content):
+            # 鑳藉鍖归厤鍒版鍒欒〃杈惧紡
+            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 r.match(r, comment_content):
+            # 鑳藉鍖归厤鍒版鍒欒〃杈惧紡
+            return True
+    return False
diff --git a/comment_util.py b/comment_util.py
new file mode 100644
index 0000000..6fdce2c
--- /dev/null
+++ b/comment_util.py
@@ -0,0 +1,125 @@
+import os
+import random
+import re
+
+import setting
+
+
+def replace_img_with_alt(html_text):
+    """
+    灏咹TML涓殑鎵�鏈�<img>鏍囩鏇挎崲涓哄叾alt灞炴�у唴瀹�
+    濡傛灉娌℃湁alt灞炴�э紝鍒欐浛鎹负绌哄瓧绗︿覆鎴栨寚瀹氶粯璁ゅ��
+    """
+    pattern = r'<img\b[^>]*\balt=(["\'])(.*?)\1[^>]*>|<img\b[^>]*>'
+
+    def replacement(match):
+        if match.group(2):  # 濡傛灉鍖归厤鍒癮lt灞炴��
+            return match.group(2)  # 杩斿洖alt灞炴�у唴瀹�
+        return ''  # 娌℃湁alt灞炴�у垯鏇挎崲涓虹┖
+
+    return re.sub(pattern, replacement, html_text, flags=re.IGNORECASE).strip()
+
+
+def get_like_conditions():
+    """
+    鑾峰彇鐐硅禐鐨勬潯浠�
+    :return:[姝e垯琛ㄨ揪寮�,...]
+    """
+    condition_str = setting.get_like_conditions()
+    return [x.split("#")[0] for x in condition_str.split("\n") if x]
+
+
+def get_comment_templates():
+    """
+    鑾峰彇璇勮妯$増
+    :return:[(鍖归厤鐨勬鍒�, 璇勮鐨勫唴瀹�)]
+    """
+    condition_str = setting.get_comment_templates()
+    return [(x.split("#")[0], x.split("#")[1]) for x in condition_str.split("\n") if x]
+
+
+def __get_common_emojis():
+    comment_emojis = setting.get_common_emojis()
+    if comment_emojis:
+        return re.findall("\[.*?\]", comment_emojis)
+    return []
+
+
+def __load_content(content_template, nick_name, comment_content):
+    """
+    鍔犺浇鍐呭
+    :param content_template:
+    :param nick_name:
+    :param comment_content:
+    :return:
+    """
+    # 鏇挎崲琛ㄦ儏
+    pattern = r'銆�([\d-]+)銆�'
+
+    def replacement_emojis(match):
+        match_str = match.group(1)
+        if match_str:
+            start = 0
+            end = 0
+            if match_str.find("-") >= 0:
+                sts = match_str.split("-")
+                if sts[0]:
+                    start = int(sts[0])
+                if sts[1]:
+                    end = int(sts[1])
+            else:
+                start = int(match_str)
+                end = int(match_str)
+            if start == 0 and end == 0:
+                return ""
+            count = random.randint(start, end)
+            result_str = ""
+            common_emojis = __get_common_emojis()
+            for i in range(count):
+                result_str += common_emojis[random.randint(0, len(common_emojis) - 1)]
+            return result_str  # 杩斿洖alt灞炴�у唴瀹�
+        return ''  # 娌℃湁alt灞炴�у垯鏇挎崲涓虹┖
+
+    result = re.sub(pattern, replacement_emojis, content_template, flags=re.IGNORECASE).strip()
+
+    comment_emojis = re.findall(r"\[.*?\]", comment_content)
+    last_emoji = ""
+    if comment_emojis:
+        last_emoji = comment_emojis[-1]
+    # 鏇挎崲鏄电О涓庡師鍐呭
+    result = result.replace("銆愭樀绉般��", nick_name).replace("銆愬唴瀹广��", comment_content).replace("銆愭渶鍚庝竴涓〃鎯呫��", last_emoji)
+    # 鏇挎崲鏈�鍚庝竴涓〃鎯�
+    return result
+
+
+def load_content(content_template, nick_name, comment_content):
+    """
+    鍔犺浇鍐呭
+    :param content_template:
+    :param nick_name:
+    :param comment_content:
+    :return:
+    """
+    # 鏇挎崲琛ㄦ儏
+    pattern = r'\{(.*?)\}'
+
+    def replacement_express(match):
+        match_str = match.group(1)
+        if match_str:
+            # 鏇挎崲鎴栬�呰〃杈惧紡
+            if match_str.find("|") >= 0:
+                sts = match_str.split("|")
+                return sts[random.randint(0, len(sts)-1)]
+            return match_str
+        return ''
+
+    result = re.sub(pattern, replacement_express, content_template, flags=re.IGNORECASE).strip()
+    # 鏇挎崲鏈�鍚庝竴涓〃鎯�
+    return __load_content(result, nick_name, comment_content)
+
+
+if __name__ == "__main__":
+    print(os.getcwd())
+    st = "{鏄殑锛屼綘鐨勮鐐瑰緢璧瀨濂藉惂[鐖卞績]|璋㈣阿[鎶辨嫵]|鏄殑[寮篯|纭疄鍙兘鏈変簺涓嶅[瑁傚紑]}"
+    comment_emojis = load_content(st,"鏄电О","璇勮鍐呭鏈韩")
+    print(comment_emojis)
diff --git a/main.py b/main.py
index 91b6942..be94b24 100644
--- a/main.py
+++ b/main.py
@@ -1,9 +1,11 @@
+import re
 import threading
 
 import wx
 
 import setting
 from comment import CommentManager
+
 
 def show_warning(content, click=None):
     toastone = wx.MessageDialog(None, content, "鎻愮ず", wx.YES_DEFAULT | wx.ICON_WARNING)
@@ -18,6 +20,7 @@
     if toastone.ShowModal() == wx.ID_YES:  # 濡傛灉鐐瑰嚮浜嗘彁绀烘鐨勭‘瀹氭寜閽�
         click()
         toastone.Destroy()
+
 
 class MainFrame(wx.Frame):
     def __bind_event(self):
@@ -69,7 +72,10 @@
             setting.set_chromedriver_path(chromedriver_path)
             setting.set_comment_templates(comment_templates)
             setting.set_reply_comment(comment)
+            setting.set_common_emojis(self.text_emojis.GetValue())
+            setting.set_like_conditions(self.text_like_conditions.GetValue())
             show_info("淇濆瓨鎴愬姛")
+
         self.Bind(wx.EVT_CLOSE, self.OnFrameClose)
         self.btn_start_comment.Bind(wx.EVT_BUTTON, start_comment)
         self.btn_chrome_path.Bind(wx.EVT_BUTTON, on_select_chrome_file)
@@ -77,69 +83,155 @@
         self.btn_save.Bind(wx.EVT_BUTTON, on_save)
 
     def __init(self):
+        self.comment_manager = None
         self.cb_like.SetValue(setting.is_click_like())
         self.cb_comment.SetValue(setting.is_reply_comment())
         self.text_comments.SetValue(setting.get_comment_templates())
         self.text_chrome_path.SetValue(setting.get_chrome_path())
         self.text_chromedriver_path.SetValue(setting.get_chromedriver_path())
+        self.text_emojis.SetValue(setting.get_common_emojis())
+        self.text_like_conditions.SetValue(setting.get_like_conditions())
 
-
-
-    def __init__(self):
+    def __create_setting_view(self, panel):
         def create_label(text):
-            return wx.StaticText(self, wx.ID_ANY, text, size=wx.Size(150, -1), style=wx.ALIGN_RIGHT)
+            return wx.StaticText(panel, wx.ID_ANY, text, size=wx.Size(150, -1), style=wx.ALIGN_RIGHT)
 
-        wx.Frame.__init__(self, None, -1, "瑙嗛鍙峰姪鎵�",
-                          size=(600, 500))
-        self.SetBackgroundColour(wx.Colour(224, 224, 224))
         boxsier = wx.BoxSizer(wx.VERTICAL)
         # 娴忚鍣ㄥ湴鍧�
         ss = wx.BoxSizer(wx.HORIZONTAL)
         ss.Add(create_label("Chrome娴忚鍣ㄨ矾寰勶細"), 0, wx.ALIGN_CENTER_VERTICAL)
-        self.text_chrome_path = wx.TextCtrl(self, wx.ID_ANY, size=wx.Size(-1, -1))
+        self.text_chrome_path = wx.TextCtrl(panel, wx.ID_ANY, size=wx.Size(-1, -1))
         ss.Add(self.text_chrome_path, 1, wx.RIGHT, 10)
-        self.btn_chrome_path = wx.Button(self, wx.ID_ANY, "閫夋嫨鏂囦欢")
+        self.btn_chrome_path = wx.Button(panel, wx.ID_ANY, "閫夋嫨鏂囦欢")
         ss.Add(self.btn_chrome_path, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
         boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
         # 娴忚鍣ㄩ┍鍔ㄥ湴鍧�
         ss = wx.BoxSizer(wx.HORIZONTAL)
         ss.Add(create_label("Chrome娴忚鍣ㄩ┍鍔ㄨ矾寰勶細"), 0, wx.ALIGN_CENTER_VERTICAL)
-        self.text_chromedriver_path = wx.TextCtrl(self, wx.ID_ANY, size=wx.Size(-1, -1))
+        self.text_chromedriver_path = wx.TextCtrl(panel, wx.ID_ANY, size=wx.Size(-1, -1))
         ss.Add(self.text_chromedriver_path, 1, wx.RIGHT, 10)
-        self.btn_chromedriver_path = wx.Button(self, wx.ID_ANY, "閫夋嫨鏂囦欢")
+        self.btn_chromedriver_path = wx.Button(panel, wx.ID_ANY, "閫夋嫨鏂囦欢")
         ss.Add(self.btn_chromedriver_path, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
         boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
 
         # 鏄惁鐐硅禐
         ss = wx.BoxSizer(wx.HORIZONTAL)
         ss.Add(create_label("鏄惁鐐硅禐锛�"), 0, wx.ALIGN_CENTER_VERTICAL)
-        self.cb_like = wx.CheckBox(self, wx.ID_ANY, "")
+        self.cb_like = wx.CheckBox(panel, wx.ID_ANY, "")
         ss.Add(self.cb_like, 0, wx.ALIGN_CENTER_VERTICAL)
         boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
 
         # 鏄惁璇勮
         ss = wx.BoxSizer(wx.HORIZONTAL)
         ss.Add(create_label("鏄惁璇勮锛�"), 0, wx.ALIGN_CENTER_VERTICAL)
-        self.cb_comment = wx.CheckBox(self, wx.ID_ANY, "")
+        self.cb_comment = wx.CheckBox(panel, wx.ID_ANY, "")
         ss.Add(self.cb_comment, 0, wx.ALIGN_CENTER_VERTICAL)
+        boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
+
+        # 甯哥敤琛ㄦ儏
+        ss = wx.BoxSizer(wx.HORIZONTAL)
+        ss.Add(create_label("甯哥敤琛ㄦ儏锛�"), 0)
+        self.text_emojis = wx.TextCtrl(panel, wx.ID_ANY, size=wx.Size(-1, 50), style=wx.TE_MULTILINE)
+        ss.Add(self.text_emojis, 1, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
         boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
 
         # 璇勮鍐呭
         ss = wx.BoxSizer(wx.HORIZONTAL)
         ss.Add(create_label("璇勮妯$増锛�"), 0)
-        self.text_comments = wx.TextCtrl(self, wx.ID_ANY, size=wx.Size(-1, 150), style=wx.TE_MULTILINE)
+        self.text_comments = wx.TextCtrl(panel, wx.ID_ANY, size=wx.Size(-1, 150), style=wx.TE_MULTILINE)
         ss.Add(self.text_comments, 1, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
         boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
-        boxsier.Add(wx.StaticText(self, wx.ID_ANY, "妯$増涓庡唴瀹逛箣闂撮噰鐢�#鍒嗛殧锛屽: 璋㈣阿$#[鏄电О]涓嶅姘擻n鍙橀噺锛歔鏄电О]\n澶囨敞锛�$-缁撳熬  ^-寮�濮�"), 0, wx.LEFT,
+        boxsier.Add(wx.StaticText(panel, wx.ID_ANY, "妯$増涓庡唴瀹逛箣闂撮噰鐢�#鍒嗛殧锛屽: 璋㈣阿$#[鏄电О]涓嶅姘擻n鍙橀噺锛氥�愭樀绉般�戯紝銆愬唴瀹广�戯紝銆愭渶鍚庝竴涓〃鎯呫�戯紝銆�1-3銆慭n澶囨敞锛�$-缁撳熬  ^-寮�濮�"), 0, wx.LEFT,
                     150)
 
-        self.btn_save = wx.Button(self, wx.ID_ANY, "淇濆瓨")
-        boxsier.Add(create_label(""))
-        boxsier.Add(self.btn_save, 0, wx.LEFT, 150)
+        # 鐐硅禐鏉′欢
+        ss = wx.BoxSizer(wx.HORIZONTAL)
+        ss.Add(create_label("鐐硅禐鏉′欢锛�"), 0)
+        self.text_like_conditions = wx.TextCtrl(panel, wx.ID_ANY, size=wx.Size(-1, 80), style=wx.TE_MULTILINE)
+        ss.Add(self.text_like_conditions, 1, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
+        boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
 
-        self.btn_start_comment = wx.Button(self, wx.ID_ANY, "寮�濮�")
-        boxsier.Add(self.btn_start_comment)
-        self.SetSizer(boxsier)
+        ss = wx.BoxSizer(wx.HORIZONTAL)
+        self.btn_save = wx.Button(panel, wx.ID_ANY, "淇濆瓨")
+        ss.Add(self.btn_save, 0, wx.LEFT, 150)
+        boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
+
+        panel.SetSizer(boxsier)
+
+    def __create_test_view(self, panel):
+        def create_label(text):
+            return wx.StaticText(panel, wx.ID_ANY, text, size=wx.Size(80, -1), style=wx.ALIGN_RIGHT)
+
+        def on_excute(evt):
+            # pattern =  self.test_regex.GetValue().encode('unicode_escape').decode("utf-8")
+            pattern = self.test_regex.GetValue()
+
+
+
+            regex = re.compile(pattern)
+            content = self.test_text.GetValue()
+            result = regex.match(content)
+            result_list=[]
+            if result:
+                result_list.append("鏄惁鍖归厤锛氬尮閰�")
+            else:
+                result_list.append("鏄惁鍖归厤锛氫笉鍖归厤")
+            result = regex.findall(content)
+            result_list.append("鍖归厤鍐呭锛�" + "锛�".join(result))
+            self.test_result.SetValue("\n".join(result_list))
+
+
+        boxsier = wx.BoxSizer(wx.VERTICAL)
+        ss = wx.BoxSizer(wx.HORIZONTAL)
+        ss.Add(create_label("姝e垯琛ㄨ揪寮忥細"), 0, wx.ALIGN_CENTER_VERTICAL)
+        self.test_regex = wx.TextCtrl(panel, wx.ID_ANY, size=wx.Size(-1, -1))
+        ss.Add(self.test_regex, 1, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
+        boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
+
+        ss = wx.BoxSizer(wx.HORIZONTAL)
+        ss.Add(create_label("鍐呭锛�"), 0)
+        self.test_text = wx.TextCtrl(panel, wx.ID_ANY, size=wx.Size(-1, 100),style=wx.TE_MULTILINE)
+        ss.Add(self.test_text, 1, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
+        boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
+
+        ss = wx.BoxSizer(wx.HORIZONTAL)
+        ss.Add(create_label("缁撴灉锛�"), 0)
+        self.test_result = wx.TextCtrl(panel, wx.ID_ANY, size=wx.Size(-1, 100), style=wx.TE_READONLY|wx.TE_MULTILINE)
+        ss.Add(self.test_result, 1, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
+        boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
+
+        ss = wx.BoxSizer(wx.HORIZONTAL)
+        ss.Add(create_label(""), 0, wx.ALIGN_CENTER_VERTICAL)
+        self.test_excute = wx.Button(panel, wx.ID_ANY, "鎵ц娴嬭瘯")
+        ss.Add(self.test_excute, 0, wx.RIGHT | wx.ALIGN_CENTER_VERTICAL, 10)
+        boxsier.Add(ss, 0, wx.EXPAND | wx.TOP, 10)
+        self.test_excute.Bind(wx.EVT_BUTTON, on_excute)
+
+        panel.SetSizer(boxsier)
+
+    def __init__(self):
+
+        wx.Frame.__init__(self, None, -1, "瑙嗛鍙峰姪鎵�",
+                          size=(900, 600))
+        self.SetBackgroundColour(wx.Colour(224, 224, 224))
+
+        root_sizer = wx.FlexGridSizer(2, 2, 10, 10)
+        # ------璁剧疆椤甸潰------
+        panel_setting = wx.Panel(self, wx.ID_ANY, size=wx.Size(500, -1))
+        self.__create_setting_view(panel_setting)
+        root_sizer.Add(panel_setting)
+
+        # ------娴嬭瘯鐣岄潰------
+        panel_test = wx.Panel(self, wx.ID_ANY, size=wx.Size(300, 400))
+        self.__create_test_view(panel_test)
+        root_sizer.Add(panel_test)
+
+        # ------鎵ц椤甸潰------
+        panel_action = wx.Panel(self, wx.ID_ANY, size=wx.Size(500, 100))
+        self.btn_start_comment = wx.Button(panel_action, wx.ID_ANY, "寮�濮�")
+        root_sizer.Add(panel_action)
+
+        self.SetSizer(root_sizer)
         self.__init()
         self.__bind_event()
 
diff --git a/res/comment.txt b/res/comment.txt
new file mode 100644
index 0000000..9f5db64
--- /dev/null
+++ b/res/comment.txt
@@ -0,0 +1,4 @@
+.*涓嶅.*#{鏄殑锛屼綘鐨勮鐐瑰緢璧瀨濂藉惂[鐖卞績]|璋㈣阿[鎶辨嫵]|鏄殑[寮篯|纭疄鍙兘鏈変簺涓嶅[瑁傚紑]}
+.*瀵�.*|.*鏀寔.*|.*娌℃瘺鐥�.*|.*涓�鏍�.*|.*娌¢敊.*|.*鏈夐亾鐞�.*#{鎰熻阿浣犵殑璁ゅ悓|鎰熻阿浣犵殑璇勪环|璋㈣阿浣犵殑璁ゅ悓|鎰熸仼浣犵殑璁ゅ悓|璋㈣阿浣犵殑璇勮|鎰熸仼浣犵殑璁ゅ彲|鏄殑锛屼綘璇寸殑娌¢敊|浣犵殑璁ゅ悓鎴戝緢鎰熸縺}{銆�1-3銆憓
+.*澶皯浜�.*#{鏄殑锛岀‘瀹炰笉澶殅{銆�1-3銆憓
+
diff --git a/res/setting.conf b/res/setting.conf
index 2e30684..22cd13a 100644
--- a/res/setting.conf
+++ b/res/setting.conf
@@ -1,7 +1,12 @@
 [config]
-comment_templates = 测试234234你好234234
+comment_templates = [*]$#[*]
+	不对#
+	对#
+	^你#123123
 reply_comment = 1
 click_like = 1
 chromedriver_path = D:\workspace\python\wechat_helper\chromedriver.exe
 chrome_path = D:\workspace\python\wechat_helper\chromedriver.exe
+common_emojis = [爱心] [合十] [拥抱] [抱拳] [强] [玫瑰] [胜利] [666] [呲牙] [愉快]
+like_conditions = [\u4e00-\u9fa5]{2,}#最少2个字中文
 
diff --git a/setting.py b/setting.py
index 0f7e781..2d62b5b 100644
--- a/setting.py
+++ b/setting.py
@@ -102,5 +102,38 @@
     return cp.get("config", "comment_templates")
 
 
+# -------------------------------甯哥敤琛ㄦ儏--------------------------
+def set_common_emojis(content):
+    # 璁剧疆鏄惁缃《
+    cp = __read_setting()
+    cp.set("config", "common_emojis", content)
+    __write_setting(cp)
+
+
+# 鑾峰彇鏄惁缃《
+def get_common_emojis():
+    try:
+        cp = __read_setting()
+        return cp.get("config", "common_emojis")
+    except:
+        return ""
+
+
+# -------------------------------鐐硅禐鏉′欢--------------------------
+def set_like_conditions(content):
+    # 璁剧疆鏄惁缃《
+    cp = __read_setting()
+    cp.set("config", "like_conditions", content)
+    __write_setting(cp)
+
+
+# 鑾峰彇鏄惁缃《
+def get_like_conditions():
+    try:
+        cp = __read_setting()
+        return cp.get("config", "like_conditions")
+    except:
+        return ""
+
 if __name__ == "__main__":
     pass
diff --git a/tool.py b/tool.py
new file mode 100644
index 0000000..539c52f
--- /dev/null
+++ b/tool.py
@@ -0,0 +1,15 @@
+
+def singleton(cls):
+    """
+    鍗曚緥瑁呴グ鍣�
+    @param cls:
+    @return:
+    """
+    instances = {}
+
+    def get_instance(*args, **kwargs):
+        if cls not in instances:
+            instances[cls] = cls(*args, **kwargs)
+        return instances[cls]
+
+    return get_instance
\ No newline at end of file
diff --git a/video_manager.py b/video_manager.py
new file mode 100644
index 0000000..eb6d74e
--- /dev/null
+++ b/video_manager.py
@@ -0,0 +1,47 @@
+import os
+import time
+
+import tool
+
+
+@tool.singleton
+class VideoManger:
+    __video_cache_path = "datas/videos.json"
+    # {"瑙嗛鍐呭+瑙嗛鏃堕棿":(璇勮鏁伴噺,鏇存柊鏃堕棿)}
+    __video_data_cache_dict = {}
+
+    def __init__(self):
+
+        if os.path.exists(self.__video_cache_path):
+            with open(self.__video_cache_path, encoding="utf-8", mode='r') as f:
+                lines = f.readlines()
+                if lines:
+                    self.__video_data_cache_dict = eval(lines[0])
+
+    def is_need_click(self, video_name, video_time, comment_count):
+        """
+        鏄惁闇�瑕佺偣鍑�
+        :param video_name: 瑙嗛鍚嶇О
+        :param video_time: 瑙嗛鏃堕棿
+        :param comment_count: 璇勮鏁伴噺
+        :return:
+        """
+        k = f"{video_name}{video_time}"
+        if k not in self.__video_data_cache_dict:
+            return True
+        if comment_count - self.__video_data_cache_dict[k][0] > 0:
+            return True
+        return False
+
+    def add_video_infos(self, video_infos):
+        """
+        娣诲姞瑙嗛淇℃伅
+        :param video_infos:
+        :return:
+        """
+        print("淇濆瓨鎵�鏈夎棰戝唴瀹�")
+        self.__video_data_cache_dict = {f"{x[0]}{x[1]}": (x[2], time.time()) for x in video_infos}
+        # 淇濆瓨鍒版枃浠�
+        with open(self.__video_cache_path, encoding="utf-8", mode='w') as f:
+            f.write(f"{self.__video_data_cache_dict}")
+

--
Gitblit v1.8.0