wangkun há 2 anos atrás
pai
commit
63dd29a71d
3 ficheiros alterados com 21 adições e 10 exclusões
  1. 3 0
      main/publish.py
  2. 1 1
      main/run_zhiqingzongqun_recommend.py
  3. 17 9
      main/zhiqingzongqun_recommend.py

+ 3 - 0
main/publish.py

@@ -8,6 +8,7 @@
 import json
 import os
 import random
+import shutil
 import time
 import oss2
 import requests
@@ -254,4 +255,6 @@ class Publish:
                 else:
                     Common.logger(log_type).error('file not a dir = {}'.format(fi_d))
             except Exception as e:
+                # 删除视频文件夹
+                shutil.rmtree("./videos/" + f + "/")
                 Common.logger(log_type).exception('upload_and_publish error', e)

+ 1 - 1
main/run_zhiqingzongqun_recommend.py

@@ -14,7 +14,7 @@ class Main:
     def main(cls, log_type, env):
         while True:
             # if datetime.datetime.now().hour >= 0:
-            if 23 >= datetime.datetime.now().hour >= 17:
+            if 23 >= datetime.datetime.now().hour >= 17 or datetime.datetime.now().hour <= 8:
                 Common.logger(log_type).info('开始抓取知青总群\n')
                 Recommend.start_wechat(log_type, env)
                 Recommend.i = 0

+ 17 - 9
main/zhiqingzongqun_recommend.py

@@ -103,8 +103,10 @@ class Recommend:
                          int(size['height'] * 0.8), 200)
             # 打开小程序"知青总群"
             time.sleep(3)
-            Common.logger(log_type).info('打开小程序"知青总群"')
-            driver.find_elements(By.XPATH, '//*[@text="知青总群"]')[-1].click()
+            # Common.logger(log_type).info('打开小程序"知青总群"')
+            Common.logger(log_type).info('打开小程序"知青天天看"')
+            # driver.find_elements(By.XPATH, '//*[@text="知青总群"]')[-1].click()
+            driver.find_elements(By.XPATH, '//*[@text="知青天天看"]')[-1].click()
             # 获取视频信息
             time.sleep(1)
             cls.get_recommend(log_type, driver, env)
@@ -156,18 +158,24 @@ class Recommend:
                 try:
                     # 切换到 webview
                     webview = driver.contexts
-                    Common.logger(log_type).info('webview:{}', webview)
+                    # Common.logger(log_type).info('webview:{}', webview)
                     Common.logger(log_type).info('切换到小程序\n')
                     # driver.switch_to.context('WEBVIEW_com.tencent.mm:appbrand0')
                     driver.switch_to.context(webview[1])
                     time.sleep(5)
-                    cls.switch_to_handle(log_type, driver, env, '知青总群')
+                    cls.switch_to_handle(log_type, driver, env, '知青天天看')
                     break
                 except Exception as e:
                     Common.logger(log_type).warning('切换到小程序失败,重启APP:{}\n', e)
                     cls.quit(log_type, driver)
                     cls.start_wechat(log_type, env)
 
+            # Common.logger(log_type).info('点击"换"按钮')
+            # try:
+            #     driver.find_element(By.XPATH, '//wx-view[@class="refreshbtnbox"]').click()
+            # except NoSuchElementException:
+            #     Common.logger(log_type).warning('未点击到"换"按钮')
+
             time.sleep(5)
             Common.logger(log_type).info('获取推荐列表视频信息')
             while True:
@@ -210,8 +218,8 @@ class Recommend:
                                 '//*[@class="videolistbox videolist--videolistbox"]'
                                 '/*[' + str(cls.i) + ']//*[@class="itemimage videolist--itemimage"]')\
                                 .get_attribute('src')
-                        except Exception as e:
-                            Common.logger(log_type).error('cover_url异常:{}', e)
+                        except Exception:
+                            # Common.logger(log_type).error('cover_url异常:{}', e)
                             cover_url = 0
 
                         # video_url
@@ -256,8 +264,8 @@ class Recommend:
                             driver.press_keycode(4)
 
                         cls.download_publish(log_type, env)
-                    except Exception as e:
-                        Common.logger(log_type).error('switch_to.window(recommend_handle)异常:{}', e)
+                    except Exception:
+                        # Common.logger(log_type).error('switch_to.window(recommend_handle)异常:{}', e)
                         pass
 
                 if cls.i == 200:
@@ -306,7 +314,7 @@ class Recommend:
                 download_comment_cnt = 0
                 download_like_cnt = 0
                 download_share_cnt = 0
-                download_user_name = '知青总群'
+                download_user_name = '知青天天看'
                 download_head_url = download_cover_url
 
                 if download_video_title is None or download_video_url is None: