Selaa lähdekoodia

developing bind with aigc syster

luojunhui 1 kuukausi sitten
vanhempi
commit
5660c79583

+ 1 - 1
applications/api/aigc_system_api.py

@@ -21,7 +21,7 @@ headers = {
 
 
 
 
 class RelationDict(TypedDict):
 class RelationDict(TypedDict):
-    contentTraceId: str
+    videoPoolTraceId: str
     channelContentId: str
     channelContentId: str
 
 
 
 

+ 10 - 0
applications/const/__init__.py

@@ -368,6 +368,16 @@ class ToutiaoVideoCrawlerConst:
     SLEEP_SECOND = 3
     SLEEP_SECOND = 3
 
 
 
 
+class SingleVideoPoolPublishTaskConst:
+    """
+    const for single video pool publish task
+    """
+    TRANSFORM_INIT_STATUS = 0
+    TRANSFORM_SUCCESS_STATUS = 1
+    TRANSFORM_FAIL_STATUS = 99
+
+
+
 
 
 
 
 
 

+ 70 - 60
coldStartTasks/publish/publish_single_video_pool_videos.py

@@ -1,23 +1,20 @@
+import json
 import datetime
 import datetime
+import traceback
+
 from pymysql.cursors import DictCursor
 from pymysql.cursors import DictCursor
+from tqdm import tqdm
 
 
 from applications import bot, aiditApi
 from applications import bot, aiditApi
+from applications.const import SingleVideoPoolPublishTaskConst
 from applications.db import DatabaseConnector
 from applications.db import DatabaseConnector
-from config import long_articles_config
+from config import long_articles_config, apolloConfig
+
+config = apolloConfig()
+const = SingleVideoPoolPublishTaskConst()
 
 
-generate_plan_map = {
-    "gzh": "20250321060236316993274",
-    "sph": "20250321055917369191992",
-    "toutiao": "20250321060107537529410",
-    "hksp": "20250321060438155415100",
-}
+video_pool_config = json.loads(config.getConfigValue(key="video_pool_config"))
 
 
-platform_name_map = {
-    "gzh": "公众号",
-    "sph": "视频号",
-    "toutiao": "头条号",
-    "hksp": "好看视频",
-}
 
 
 class PublishSingleVideoPoolVideos:
 class PublishSingleVideoPoolVideos:
     def __init__(self):
     def __init__(self):
@@ -25,24 +22,13 @@ class PublishSingleVideoPoolVideos:
         self.db_client.connect()
         self.db_client.connect()
 
 
     def get_task_list(self, platform:str) -> list[dict]:
     def get_task_list(self, platform:str) -> list[dict]:
-        match platform:
-            case "sph":
-                task_count = 218
-            case "gzh":
-                task_count = 201
-            case "toutiao":
-                task_count = 411
-            case "hksp":
-                task_count = 165
-            case _:
-                return []
-
+        daily_limit = video_pool_config[platform]['process_num_each_day']
         fetch_query = f"""
         fetch_query = f"""
             select id, content_trace_id, pq_vid
             select id, content_trace_id, pq_vid
             from single_video_transform_queue
             from single_video_transform_queue
-            where status = 0 and platform = '{platform}'
+            where status = {const.TRANSFORM_INIT_STATUS} and platform = '{platform}'
             order by score desc
             order by score desc
-            limit 2000
+            limit {daily_limit};
         """
         """
         fetch_response = self.db_client.fetch(query=fetch_query, cursor_type=DictCursor)
         fetch_response = self.db_client.fetch(query=fetch_query, cursor_type=DictCursor)
         return fetch_response
         return fetch_response
@@ -67,41 +53,65 @@ class PublishSingleVideoPoolVideos:
         entrance of this class
         entrance of this class
         """
         """
         platform_list = ["sph", "gzh", "toutiao", "hksp"]
         platform_list = ["sph", "gzh", "toutiao", "hksp"]
-        for platform in platform_list:
+        for platform in tqdm(platform_list, desc='process each platform'):
             task_list = self.get_task_list(platform)
             task_list = self.get_task_list(platform)
             task_id_tuple = tuple([task['id'] for task in task_list])
             task_id_tuple = tuple([task['id'] for task in task_list])
             vid_list = [task['pq_vid'] for task in task_list]
             vid_list = [task['pq_vid'] for task in task_list]
             if vid_list:
             if vid_list:
-                # create video crawler plan
-                plan_name = f"{platform_name_map[platform]}-{datetime.datetime.today().strftime('%Y-%m-%d')}-视频数量: {len(vid_list)}"
-                crawler_plan_response = aiditApi.auto_create_single_video_crawler_task(
-                    plan_name=plan_name,
-                    plan_tag="单视频供给冷启动",
-                    video_id_list=vid_list,
-                )
-                crawler_plan_id = crawler_plan_response["data"]["id"]
-                crawler_plan_name = crawler_plan_response["data"]["name"]
-                # update status
-                self.update_tasks_status(
-                    task_id_tuple=task_id_tuple,
-                    ori_status=0,
-                    new_status=1,
-                )
-                # bind crawler plan to generate plan
-                crawler_task_list = [
-                    {
-                        "contentType": 1,
-                        "inputSourceModal": 4,
-                        "inputSourceChannel": 10,
-                        "inputSourceType": 2,
-                        "inputSourceValue": crawler_plan_id,
-                        "inputSourceSubType": None,
-                        "fieldName": None,
-                        "inputSourceLabel": "原始帖子-视频-票圈小程序-内容添加计划-{}".format(crawler_plan_name),
-                    }
-                ]
-                generate_plan_id = generate_plan_map[platform]
-                aiditApi.bind_crawler_task_to_generate_task(
-                    crawler_task_list=crawler_task_list,
-                    generate_task_id=generate_plan_id,
+                try:
+                    # create video crawler plan
+                    plan_name = f"{video_pool_config[platform]['nick_name']}-{datetime.datetime.today().strftime('%Y-%m-%d')}-视频数量: {len(vid_list)}"
+                    crawler_plan_response = aiditApi.auto_create_single_video_crawler_task(
+                        plan_name=plan_name,
+                        plan_tag="单视频供给冷启动",
+                        video_id_list=vid_list,
+                    )
+                    crawler_plan_id = crawler_plan_response["data"]["id"]
+                    crawler_plan_name = crawler_plan_response["data"]["name"]
+
+                    # bind crawler plan to generate plan
+                    crawler_task_list = [
+                        {
+                            "contentType": 1,
+                            "inputSourceModal": 4,
+                            "inputSourceChannel": 10,
+                            "inputSourceType": 2,
+                            "inputSourceValue": crawler_plan_id,
+                            "inputSourceSubType": None,
+                            "fieldName": None,
+                            "inputSourceLabel": "原始帖子-视频-票圈小程序-内容添加计划-{}".format(crawler_plan_name),
+                        }
+                    ]
+                    generate_plan_id = video_pool_config[platform]['generate_plan_id']
+                    aiditApi.bind_crawler_task_to_generate_task(
+                        crawler_task_list=crawler_task_list,
+                        generate_task_id=generate_plan_id,
+                    )
+
+                    # update status
+                    self.update_tasks_status(
+                        task_id_tuple=task_id_tuple,
+                        ori_status=const.TRANSFORM_INIT_STATUS,
+                        new_status=const.TRANSFORM_SUCCESS_STATUS
+                    )
+                except Exception as e:
+                    bot(
+                        title='视频内容池发布任务',
+                        detail={
+                            'platform': platform,
+                            'date': datetime.datetime.today().strftime('%Y-%m-%d'),
+                            'msg': '发布视频内容池失败,原因:{}'.format(str(e)),
+                            'detail': traceback.format_exc(),
+                        },
+                        mention=False
+                    )
+            else:
+                bot(
+                    title='视频内容池发布任务',
+                    detail={
+                        'platform': platform,
+                        'date': datetime.datetime.today().strftime('%Y-%m-%d'),
+                        'msg': '该平台无待发布视频,请关注供给的抓取'
+                    },
+                    mention=False
                 )
                 )

+ 1 - 1
coldStartTasks/publish/publish_video_to_pq_for_audit.py

@@ -247,7 +247,7 @@ class PublishVideosForAudit(object):
                 aigc.insert_crawler_relation_to_aigc_system(
                 aigc.insert_crawler_relation_to_aigc_system(
                     relation_list=[
                     relation_list=[
                         {
                         {
-                            "contentTraceId": video_obj['content_trace_id'],
+                            "videoPoolTraceId": video_obj['content_trace_id'],
                             "channelContentId": str(video_id)
                             "channelContentId": str(video_id)
                         }
                         }
                     ]
                     ]