Browse Source

add weixinzhishu: search_key

wangkun 2 years ago
parent
commit
f04d477813
1 changed files with 8 additions and 5 deletions
  1. 8 5
      weixinzhishu/weixinzhishu_main/search_key.py

+ 8 - 5
weixinzhishu/weixinzhishu_main/search_key.py

@@ -16,7 +16,7 @@ class Searchkey:
     @classmethod
     def start_wechat(cls, log_type, crawler):
         try:
-            Common.logger(log_type, crawler).info('启动"微信"')
+            # Common.logger(log_type, crawler).info('启动"微信"')
             # print('启动"微信"')
             desired_caps = {'app': r"C:\Program Files (x86)\Tencent\WeChat\WeChat.exe"}
             driver = webdriver.Remote(
@@ -30,9 +30,9 @@ class Searchkey:
             # Common.logger(log_type).info('点击"爬虫群"')
             # driver.find_elements(By.NAME, '爬虫群')[0].click()
 
-            Common.logger(log_type, crawler).info('点击微信指数')
+            # Common.logger(log_type, crawler).info('点击微信指数')
             driver.find_elements(By.NAME, '消息')[-1].click()
-            Common.logger(log_type, crawler).info('休眠 3 秒,退出微信')
+            # Common.logger(log_type, crawler).info('休眠 3 秒,退出微信')
             time.sleep(3)
             driver.quit()
         except Exception as e:
@@ -47,9 +47,9 @@ class Searchkey:
             all_file = os.listdir(chlsfile_path)
             chlsfile_list = []
             if len(all_file) == 0:
-                Common.logger(log_type, crawler).info("chlsfile文件夹为空,等待2s")
+                Common.logger(log_type, crawler).info("chlsfile文件夹为空,等待10s")
                 cls.start_wechat(log_type, crawler)
-                time.sleep(2)
+                time.sleep(10)
                 cls.get_search_key(log_type, crawler)
             else:
                 for file in all_file:
@@ -60,6 +60,7 @@ class Searchkey:
             if len(chlsfile_list) == 0:
                 Common.logger(log_type, crawler).info('未找到chlsfile文件,重新获取')
                 cls.start_wechat(log_type, crawler)
+                time.sleep(10)
                 cls.get_search_key(log_type, crawler)
             else:
                 # 获取最新的 chlsfile
@@ -123,9 +124,11 @@ class Searchkey:
             search_key = cls.get_search_key(log_type, crawler)
             if search_key is None or search_key == "未找到search_key":
                 time.sleep(3)
+                Common.logger(log_type, crawler).info('未找到search_key,重启打开微信指数,获取 search_key')
                 cls.start_wechat(log_type, crawler)
                 cls.get_search_key(log_type, crawler)
             else:
+                Common.logger(log_type, crawler).info(f'已获取 search_key:{search_key}')
                 Feishu.insert_columns(log_type, crawler, 'sVL74k', 'ROWS', 1, 2)
                 time.sleep(1)
                 time_str = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(time.time())))