浏览代码

管理后台增加定时任务

zhangyong 1 年之前
父节点
当前提交
881e88c7e3
共有 5 个文件被更改,包括 39 次插入7 次删除
  1. 6 0
      common/feishu.py
  2. 9 0
      common/material.py
  3. 1 1
      main.py
  4. 1 1
      video_capture/douyin/douyin_author/douyin_author.py
  5. 22 5
      video_stitching/video_stitching.py

+ 6 - 0
common/feishu.py

@@ -332,6 +332,12 @@ class Feishu:
                 sheet_url = "https://w42nne6hzg.feishu.cn/sheets/CPDNs06R2hux6SthZ1wcQmkAnYg?sheet=OpE35G"
                 users = "\n<at id=" + str(cls.get_userid(log_type, crawler, "wangxueke")) + "></at> <at id=" + str(
                     cls.get_userid(log_type, crawler, "muxinyi")) + "></at>\n"
+            elif crawler == "管理后台":
+                content = "管理后台cookie过期"
+                sheet_url = "https://w42nne6hzg.feishu.cn/sheets/CPDNs06R2hux6SthZ1wcQmkAnYg?sheet=OpE35G"
+                users = "\n<at id=" + str(cls.get_userid(log_type, crawler, "wangxueke")) + "></at> <at id=" + str(
+                    cls.get_userid(log_type, crawler, "muxinyi")) + "></at>\n"
+
 
             data = json.dumps({
                 "msg_type": "interactive",

+ 9 - 0
common/material.py

@@ -69,6 +69,15 @@ class Material():
             if item[0] == '抖音':
                 return item[1]
 
+    @classmethod
+    def get_houtai_cookie(cls):
+        douyin_token = Feishu.get_values_batch("prod", "succinct", "OpE35G")
+        for item in douyin_token:
+            if item[0] == '管理后台':
+                return item[1]
+
+
+
 
 
 

+ 1 - 1
main.py

@@ -9,7 +9,7 @@ import schedule
 import time
 
 def job_video_stitching():
-    VideoStitching.video_stitching()
+    VideoStitching.video_cookie()
 
 def job_douyin_data():
     douyinAuthor.get_token()

+ 1 - 1
video_capture/douyin/douyin_author/douyin_author.py

@@ -111,7 +111,7 @@ class douyinAuthor():
                 response.close()
                 if response.status_code != 200:
                     Common.logger().info(
-                        f"接口请求失败,请更换cookie,{response.status_code}")
+                        f"接口请求失败,请更换cookie,{response.status_code}")
                     Feishu.bot('recommend', '抖音', '抖音cookie失效,请及时更换~')
                     # 如果返回空信息,则随机睡眠 600, 1200 秒
                     time.sleep(random.randint(600, 1200))

+ 22 - 5
video_stitching/video_stitching.py

@@ -9,8 +9,10 @@ import subprocess
 
 import requests
 import urllib.parse
-sys.path.append(os.getcwd())
 
+
+sys.path.append(os.getcwd())
+from common import Feishu
 from common.aliyun_oss_uploading import Oss
 from common.common import Common
 from common.db import MysqlHelper
@@ -224,7 +226,7 @@ class VideoStitching():
 
 
     @classmethod
-    def get_audio_url(cls, i):
+    def get_audio_url(cls, i, cookie):
         url = f"https://admin.piaoquantv.com/manager/video/detail/{i}"
 
         payload = {}
@@ -233,7 +235,7 @@ class VideoStitching():
             'accept': 'application/json, text/plain, */*',
             'accept-language': 'zh-CN,zh;q=0.9',
             'cache-control': 'no-cache',
-            'cookie': 'SESSION=MDJiNGM4YzgtY2RiMC00ZjRkLThlNzEtOThhZDJkMjE0Yzgx',
+            'cookie': cookie,
             'pragma': 'no-cache',
             'referer': f'https://admin.piaoquantv.com/cms/post-detail/{i}/detail',
             'sec-ch-ua': '"Not_A Brand";v="8", "Chromium";v="120", "Google Chrome";v="120"',
@@ -247,12 +249,21 @@ class VideoStitching():
 
         response = requests.request("GET", url, headers=headers, data=payload)
         data = response.json()
+        code = data["code"]
+        if code == 10:
+            Common.logger().info(
+                f"未登录,请更换cookie,{data}")
+            Feishu.bot('recommend', '管理后台', '管理后台cookie失效,请及时更换~')
+            # 如果返回空信息,则随机睡眠 600, 1200 秒
+            time.sleep(random.randint(600, 1200))
+            cls.video_cookie()
+
         audio_url = data["content"]["transedVideoPath"]
         print(audio_url)
         return audio_url
 
     @classmethod
-    def video_stitching(cls):
+    def video_stitching(cls, cookie):
         count = 0
         # 获取音频
         audio = Material.get_audio()
@@ -265,7 +276,7 @@ class VideoStitching():
                 # 获取 未使用的视频链接
                 url_list = cls.get_url_list(i, account)
                 # 获取音频url
-                audio = cls.get_audio_url(i)
+                audio = cls.get_audio_url(i, cookie)
                 Common.logger().info(f"获取音频地址:{audio}")
                 videos = [list(item) for item in url_list]
                 videos = Oss.get_oss_url(videos)
@@ -306,6 +317,12 @@ class VideoStitching():
             if count >= 20:
                 break
 
+    @classmethod
+    def video_cookie(cls):
+        # 获取后台cookie
+        cookie = Material.get_houtai_cookie()
+        cls.video_stitching(cookie)
+