فهرست منبع

兼容新服务&&参数校验

罗俊辉 1 سال پیش
والد
کامیت
4bb705d20c
3فایلهای تغییر یافته به همراه102 افزوده شده و 36 حذف شده
  1. 49 35
      applications/routes.py
  2. 2 1
      applications/schedule/__init__.py
  3. 51 0
      applications/schedule/process_schedule.py

+ 49 - 35
applications/routes.py

@@ -8,7 +8,7 @@ import asyncio
 from quart import Blueprint, jsonify, request
 
 from applications.functions.log import logging
-from applications.schedule import recall_videos, search_videos
+from applications.schedule import recall_videos, search_videos, return_info_v2
 
 my_blueprint = Blueprint('LongArticles', __name__)
 
@@ -38,46 +38,60 @@ def Routes(mysql_client):
         :return:
         """
         params = await request.get_json()
-        gh_id = params['ghId']
-        trace_id = "search-{}-{}".format(str(uuid.uuid4()), str(int(time.time())))
-        params['trace_id'] = trace_id
-        title = params['title'].split("@@")[-1].replace("'", "")
-        contents = params['content'].replace("'", "")
-        account_name = params['accountName'].replace("'", "")
-        logging(
-            code="2000",
-            info="搜索视频内容接口请求成功",
-            port="title_to_search",
-            function="search_videos_from_the_web",
-            trace_id=trace_id
-        )
-        insert_sql = f"""
-            INSERT INTO long_articles_video 
-                (trace_id, gh_id, article_title, article_text, account_name)
-            VALUES 
-                ('{trace_id}', '{gh_id}', '{title}', '{contents}', '{account_name}');"""
-        await mysql_client.async_insert(insert_sql)
         try:
-            asyncio.ensure_future(
-                search_videos(
-                    params=params,
-                    trace_id=trace_id,
-                    gh_id=gh_id,
-                    mysql_client=mysql_client
-                )
+            gh_id = params['ghId']
+            trace_id = "search-{}-{}".format(str(uuid.uuid4()), str(int(time.time())))
+            params['trace_id'] = trace_id
+            title = params['title'].split("@@")[-1].replace("'", "")
+            contents = params['content'].replace("'", "")
+            account_name = params['accountName'].replace("'", "")
+            logging(
+                code="2000",
+                info="搜索视频内容接口请求成功",
+                port="title_to_search",
+                function="search_videos_from_the_web",
+                trace_id=trace_id
             )
-            res = {
-                "status": "success",
-                "code": 0,
-                "traceId": trace_id
-            }
         except Exception as e:
-            res = {
+            result = {
                 "status": "fail",
                 "code": 1,
-                "message": str(e)
+                "message": str(e),
+                "info": "params check error"
             }
-        return jsonify(res)
+            return jsonify(result)
+        if "video_id=" in title:
+            video_id = title.split("video_id=")[-1]
+            result = await return_info_v2(video_id=video_id, trace_id=trace_id)
+            return jsonify(result)
+        else:
+            insert_sql = f"""
+                INSERT INTO long_articles_video 
+                    (trace_id, gh_id, article_title, article_text, account_name)
+                VALUES 
+                    ('{trace_id}', '{gh_id}', '{title}', '{contents}', '{account_name}');"""
+            await mysql_client.async_insert(insert_sql)
+            try:
+                asyncio.ensure_future(
+                    search_videos(
+                        params=params,
+                        trace_id=trace_id,
+                        gh_id=gh_id,
+                        mysql_client=mysql_client
+                    )
+                )
+                res = {
+                    "status": "success",
+                    "code": 0,
+                    "traceId": trace_id
+                }
+            except Exception as e:
+                res = {
+                    "status": "fail",
+                    "code": 1,
+                    "message": str(e)
+                }
+            return jsonify(res)
 
     @my_blueprint.route('/recall_videos', methods=['POST'])
     async def find_videos():

+ 2 - 1
applications/schedule/__init__.py

@@ -2,4 +2,5 @@
 @author: luojunhui
 """
 from .process_schedule import recall_videos
-from .search_schedule import search_videos
+from .search_schedule import search_videos
+from .process_schedule import return_info_v2

+ 51 - 0
applications/schedule/process_schedule.py

@@ -8,6 +8,57 @@ from applications.functions.common import request_for_info, create_gzh_path
 from applications.functions.log import logging
 
 
+async def return_info_v2(video_id, trace_id):
+    """
+    :param trace_id:
+    :param video_id:
+    :return:
+    """
+    response = request_for_info(video_id)
+    productionCover = response['data'][0]['shareImgPath']
+    productionName = response['data'][0]['title']
+    videoUrl = response['data'][0]['videoPath']
+    user_id = response['data'][0]['user']['uid']
+    programAvatar = "https://rescdn.yishihui.com/0temp/lehuo.png"
+    programId = "wxe8f8f0e23cecad0f"
+    programName = "票圈乐活"
+    source = "PQ"
+    root_share_id, source_id, productionPath = create_gzh_path(video_id=video_id, shared_uid=user_id)
+    logging(
+        code="1002",
+        info="root_share_id --{}, productionPath -- {}".format(root_share_id, productionPath),
+        function="process",
+        trace_id=trace_id
+    )
+    result = {
+        "productionCover": productionCover,
+        "productionName": productionName,
+        "programAvatar": programAvatar,
+        "programId": programId,
+        "programName": programName,
+        "source": source,
+        "rootShareId": root_share_id,
+        "productionPath": productionPath,
+        "videoUrl": videoUrl,
+        "paragraphPosition": 0.25
+    }
+    logging(
+        code="2000",
+        info="root_share_id和source_id",
+        function="process",
+        trace_id=trace_id,
+        data={
+            "rootShareId": root_share_id,
+            "videoId": video_id,
+            "sourceId": source_id
+        }
+    )
+    return {
+        "traceId": trace_id,
+        "miniprogramList": [result]
+    }
+
+
 async def return_info(video_id, kimi_title, trace_id, mysql_client, index):
     """