Browse Source

定时任务调试

zhangyong 1 year ago
parent
commit
8ddd28b930
3 changed files with 70 additions and 66 deletions
  1. 1 1
      common/aliyun_oss_uploading.py
  2. 37 37
      main.py
  3. 32 28
      video_stitching/video_stitching.py

+ 1 - 1
common/aliyun_oss_uploading.py

@@ -9,7 +9,7 @@ import requests
 OSS_BUCKET_PATH = "douyin"
 OSS_ACCESS_KEY_ID = "LTAI5t9FaRSZZX2n6cnvhveb"
 OSS_ACCESS_KEY_SECRET = "VvMH6NkfByov57RWzBi4lKPdfrpdVu"
-OSS_BUCKET_ENDPOINT = "oss-cn-hangzhou.aliyuncs.com" # 外网地址上到服务器需要更改为内网地址
+OSS_BUCKET_ENDPOINT = "oss-cn-hangzhou-internal.aliyuncs.com" # 外网地址上到服务器需要更改为内网地址
 OSS_BUCKET_NAME = "art-crawler"
 class Oss():
     # 抓取视频上传到art-crawler

+ 37 - 37
main.py

@@ -1,41 +1,41 @@
 import os
 import sys
-# import threading
-# import schedule
-# import time
+import threading
+import schedule
+import time
 sys.path.append(os.getcwd())
-# from common.db import MysqlHelper
-# from video_capture.douyin.douyin_author.douyin_author import douyinAuthor
+from common.db import MysqlHelper
+from video_capture.douyin.douyin_author.douyin_author import douyinAuthor
 from video_stitching.video_stitching import VideoStitching
-# from datetime import datetime, timedelta
-VideoStitching.video_stitching()
-#
-# def get_count():
-#     current_time = datetime.now()
-#     previous_time = current_time - timedelta(minutes=10)
-#     previous_time_str = previous_time.strftime("%Y-%m-%d %H:%M")
-#     select_user_sql = f"""select video_id from video_url where time >="{previous_time_str}";"""
-#     count = MysqlHelper.get_values(select_user_sql, "prod")
-#     if count:
-#         return True
-#     else:
-#         return False
-#
-# def check_token():
-#     while True:
-#         count = get_count()
-#         if count:
-#             time.sleep(1200)  # 每20分钟检查一次
-#         else:
-#             douyinAuthor.get_token()
-#
-# # 创建并启动线程
-# token_thread = threading.Thread(target=check_token)
-# token_thread.start()
-#
-# # 每天下午4点定时启动 video_stitching 方法
-# schedule.every().day.at("16:00").do(VideoStitching.video_stitching())
-#
-# while True:
-#     schedule.run_pending()
-#     time.sleep(1)
+from datetime import datetime, timedelta
+
+def get_count():
+    current_time = datetime.now()
+    previous_time = current_time - timedelta(minutes=10)
+    previous_time_str = previous_time.strftime("%Y-%m-%d %H:%M")
+    select_user_sql = f"""select video_id from video_url where time >="{previous_time_str}";"""
+    count = MysqlHelper.get_values(select_user_sql, "prod")
+    if count:
+        return True
+    else:
+        return False
+
+def check_token():
+    while True:
+        count = get_count()
+        if count:
+            time.sleep(1200)  # 每20分钟检查一次
+        else:
+            douyinAuthor.get_token()
+
+# 创建并启动线程
+token_thread = threading.Thread(target=check_token)
+token_thread.start()
+
+# 每天下午4点定时启动 video_stitching 方法
+schedule.every().day.at("16:00").do(VideoStitching.video_stitching())
+
+
+while True:
+    schedule.run_pending()
+    time.sleep(1)

+ 32 - 28
video_stitching/video_stitching.py

@@ -83,34 +83,38 @@ class VideoStitching():
     # 新生成视频上传到对应账号下
     @classmethod
     def insert_piaoquantv(cls, oss_object_key):
-        title = Material.get_title()
-        url = "https://vlogapi.piaoquantv.com/longvideoapi/crawler/video/send"
-        payload = dict(pageSource='vlog-pages/post/post-video-post', videoPath=oss_object_key, width='720',
-                       height='1280', fileExtensions='mp4', viewStatus='1', title=title, careModelStatus='1',
-                       token='f04f58d6e664cbc9902660a1e8d20ce6cd7fdb0f', loginUid='66425096', versionCode='719',
-                       machineCode='weixin_openid_o0w175aZ4FJtqVsA1tcozJDJHdDU', appId='wx89e7eb06478361d7',
-                       clientTimestamp='1703337579331',
-                       machineInfo='{"sdkVersion":"3.2.5","brand":"iPhone","language":"zh_CN","model":"iPhone 12 Pro<iPhone13,3>","platform":"ios","system":"iOS 15.6.1","weChatVersion":"8.0.44","screenHeight":844,"screenWidth":390,"pixelRatio":3,"windowHeight":762,"windowWidth":390,"softVersion":"4.1.719"}',
-                       sessionId='1703337560040-27bfe208-a389-f476-db1d-840681e04b32',
-                       subSessionId='1703337569952-8f56d53c-b36d-760e-8abe-0b4a027cd5bd', senceType='1089',
-                       hotSenceType='1089', id='1050', channel='pq')
-
-        payload['videoPath'] = oss_object_key
-        payload['title'] = title
-
-        data = urllib.parse.urlencode(payload)
-
-        headers = {
-            'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.44(0x18002c2d) NetType/WIFI Language/zh_CN',
-            'Accept-Encoding': 'gzip,compress,br,deflate',
-            'Referer': 'https://servicewechat.com/wx89e7eb06478361d7/726/page-frame.html',
-            'Content-Type': 'application/x-www-form-urlencoded',
-            'Cookie': 'JSESSIONID=A60D96E7A300A25EA05425B069C8B459'
-        }
-
-        response = requests.post(url, data=data, headers=headers)
-        data = response.json()
-        if data["code"] == 0:
+        code = 1
+        list = ["66481136", "66481137", "66481140", "66481141", "66481142"]
+        for item in list:
+            title = Material.get_title()
+            url = "https://vlogapi.piaoquantv.com/longvideoapi/crawler/video/send"
+            payload = dict(pageSource='vlog-pages/post/post-video-post', videoPath=oss_object_key, width='720',
+                           height='1280', fileExtensions='mp4', viewStatus='1', title=title, careModelStatus='1',
+                           token='f04f58d6e664cbc9902660a1e8d20ce6cd7fdb0f', loginUid=item, versionCode='719',
+                           machineCode='weixin_openid_o0w175aZ4FJtqVsA1tcozJDJHdDU', appId='wx89e7eb06478361d7',
+                           clientTimestamp='1703337579331',
+                           machineInfo='{"sdkVersion":"3.2.5","brand":"iPhone","language":"zh_CN","model":"iPhone 12 Pro<iPhone13,3>","platform":"ios","system":"iOS 15.6.1","weChatVersion":"8.0.44","screenHeight":844,"screenWidth":390,"pixelRatio":3,"windowHeight":762,"windowWidth":390,"softVersion":"4.1.719"}',
+                           sessionId='1703337560040-27bfe208-a389-f476-db1d-840681e04b32',
+                           subSessionId='1703337569952-8f56d53c-b36d-760e-8abe-0b4a027cd5bd', senceType='1089',
+                           hotSenceType='1089', id='1050', channel='pq')
+
+            payload['videoPath'] = oss_object_key
+            payload['title'] = title
+
+            data = urllib.parse.urlencode(payload)
+
+            headers = {
+                'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 15_6_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148 MicroMessenger/8.0.44(0x18002c2d) NetType/WIFI Language/zh_CN',
+                'Accept-Encoding': 'gzip,compress,br,deflate',
+                'Referer': 'https://servicewechat.com/wx89e7eb06478361d7/726/page-frame.html',
+                'Content-Type': 'application/x-www-form-urlencoded',
+                'Cookie': 'JSESSIONID=A60D96E7A300A25EA05425B069C8B459'
+            }
+
+            response = requests.post(url, data=data, headers=headers)
+            data = response.json()
+            code = data["code"]
+        if code == 0:
             return True
         else:
             return False