luojunhui 1 день назад
Родитель
Сommit
162ecb00b7

+ 0 - 0
app/domains/decode_task/__init__.py


+ 0 - 0
app/domains/decode_task/ad_platform_articles_decode/__init__.py


+ 30 - 0
app/domains/decode_task/ad_platform_articles_decode/_const.py

@@ -0,0 +1,30 @@
+
+
+class AdPlatformArticlesDecodeConst:
+    # 解构任务状态
+    DECODE_INIT_STATUS = 0
+    DECODE_PROCESSING_STATUS = 1
+    DECODE_SUCCESS_STATUS = 2
+    DECODE_FAILED_STATUS = 99
+
+    # 解构结果状态
+    PENDING = 0
+    RUNNING = 1
+    SUCCESS = 2
+    FAILED = 3
+
+    # 业务场景
+    POINT_PICK = 0
+    CREATE = 1
+    MAKE = 2
+
+    # 内容类型
+    LONG_ARTICLE = 1
+    PICTURE_TEXT = 2
+    VIDEO = 3
+
+    # 返回 code
+    SUCCESS_CODE = 0
+
+
+

+ 9 - 0
app/domains/decode_task/ad_platform_articles_decode/_mapper.py

@@ -0,0 +1,9 @@
+from app.core.database import DatabaseManager
+
+
+class AdPlatformArticlesDecodeMapper:
+
+    def __init__(self, pool: DatabaseManager):
+        self.pool = pool
+
+

+ 18 - 0
app/domains/decode_task/ad_platform_articles_decode/_util.py

@@ -0,0 +1,18 @@
+import json
+
+from app.infra.internal import DecodeServer
+
+
+class AdPlatformArticlesDecodeUtil:
+
+    decode_server = DecodeServer()
+
+    @staticmethod
+    def format_images(images: str):
+        """
+        格式化图片字符串
+        """
+        image_list = json.loads(images)
+        return [i["image_url"] for i in image_list]
+
+

+ 16 - 0
app/domains/decode_task/ad_platform_articles_decode/entrance.py

@@ -0,0 +1,16 @@
+from app.core.database import DatabaseManager
+from app.core.observability import LogService
+
+from ._const import AdPlatformArticlesDecodeConst
+from ._mapper import AdPlatformArticlesDecodeMapper
+from ._util import AdPlatformArticlesDecodeUtil
+
+
+class AdPlatformArticlesDecodeTask(AdPlatformArticlesDecodeConst):
+
+    def __init__(self, pool: DatabaseManager, log_service: LogService):
+        self.pool = pool
+        self.log_service = log_service
+        self.mapper = AdPlatformArticlesDecodeMapper(self.pool)
+        self.tool = AdPlatformArticlesDecodeUtil()
+

+ 2 - 0
app/infra/internal/__init__.py

@@ -2,6 +2,7 @@
 from .piaoquan import change_video_audit_status
 from .piaoquan import publish_video_to_piaoquan
 from .piaoquan import fetch_piaoquan_video_list_detail
+from .piaoquan import DecodeServer
 
 # aigc system api
 from .aigc_system import delete_illegal_gzh_articles
@@ -25,4 +26,5 @@ __all__ = [
     "get_titles_from_produce_plan",
     "get_top_article_title_list",
     "get_hot_titles",
+    "DecodeServer",
 ]

+ 65 - 0
app/infra/internal/piaoquan.py

@@ -76,3 +76,68 @@ async def publish_video_to_piaoquan(oss_path: str, uid: str, title: str) -> Dict
         response = await client.post(url, data=payload, headers=headers)
 
     return response
+
+
+class DecodeServer:
+
+    base_url: str = "http://supply-content-deconstruction-api.piaoquantv.com"
+
+    # 创建解构任务
+    async def create_decode_task(self, data: Dict) -> Dict:
+        """
+        scene: 业务场景:0 选题; 1 创作; 2 制作;
+        content_type: 内容类型: 1 长文; 2 图文; 3 视频;
+        content:
+            channel_content_id:
+            video_url:
+            images: [ image_url_1, image_url_2, ...]
+            body_text: 长文内容
+            title: 文章标题
+            channel_account_id: 作者 id
+            channel_account_name: 作者名称
+        output_type: {
+
+        }
+        """
+        url = f"{self.base_url}/api/v1/content/tasks/decode"
+        headers = {
+            "User-Agent": "PQSpeed/486 CFNetwork/1410.1 Darwin/22.6.0",
+            "Content-Type": "application/json",
+        }
+        async with AsyncHttpClient() as client:
+            response = await client.post(url, json=data, headers=headers)
+
+        return response
+
+    # 获取解构结果
+    async def fetch_decode_result(self, task_id: str) -> Dict:
+        """
+        INPUT: TaskId
+        OUTPUT: Dict
+        {
+          code: 0 | 404(task not exist),
+          msg: 'ok',
+          data: {
+              "taskId": "123",
+              "status": 3, 0 PENDING, 1 RUNNING, 2 SUCCESS, 3 FAILED
+              "result": None | JSON,
+              "reason": "" | 失败原因,
+              "url": {
+                  "pointUrl": "", 选题点结构结果页地址(仅解构任务有
+                  "weightUrl": "", 权重页地址(解构聚类都有)
+                  "patternUrl": "" 选题点聚类结果页地址(仅聚类任务有)
+              }
+          },
+        }
+        """
+        url = f"{self.base_url}/api/v1/content/tasks/{task_id}"
+        headers = {
+            "User-Agent": "PQSpeed/486 CFNetwork/1410.1 Darwin/22.6.0",
+            "Content-Type": "application/json",
+        }
+        async with AsyncHttpClient() as client:
+            response = await client.get(url, headers=headers)
+
+        return response
+
+