瀏覽代碼

return_3_cards v1

罗俊辉 11 月之前
父節點
當前提交
2e7b0b232f
共有 4 個文件被更改,包括 163 次插入110 次删除
  1. 2 2
      applications/routes.py
  2. 82 57
      applications/schedule/process_schedule.py
  3. 72 45
      applications/schedule/search_schedule.py
  4. 7 6
      dev/test_v2.py

+ 2 - 2
applications/routes.py

@@ -54,7 +54,7 @@ def Routes(mysql_client):
             trace_id=trace_id
             trace_id=trace_id
         )
         )
         insert_sql = f"""
         insert_sql = f"""
-            INSERT INTO long_articles_video 
+            INSERT INTO long_articles_video_dev 
                 (trace_id, gh_id, article_title, article_text, account_name)
                 (trace_id, gh_id, article_title, article_text, account_name)
             VALUES 
             VALUES 
                 ('{trace_id}', '{gh_id}', '{title}', '{contents}', '{account_name}');"""
                 ('{trace_id}', '{gh_id}', '{title}', '{contents}', '{account_name}');"""
@@ -66,7 +66,7 @@ def Routes(mysql_client):
             content_title = kimi_info['content_title']
             content_title = kimi_info['content_title']
             content_keys = json.dumps(kimi_info['content_keys'], ensure_ascii=False)
             content_keys = json.dumps(kimi_info['content_keys'], ensure_ascii=False)
             update_kimi_sql = f"""
             update_kimi_sql = f"""
-                UPDATE long_articles_video SET
+                UPDATE long_articles_video_dev SET
                 kimi_title = '{kimi_title}',
                 kimi_title = '{kimi_title}',
                 kimi_summary = '{content_title}',
                 kimi_summary = '{content_title}',
                 kimi_keys = '{content_keys}'
                 kimi_keys = '{content_keys}'

+ 82 - 57
applications/schedule/process_schedule.py

@@ -8,77 +8,102 @@ from applications.functions.common import request_for_info, create_gzh_path
 from applications.functions.log import logging
 from applications.functions.log import logging
 
 
 
 
+async def return_info(video_id, kimi_title, trace_id, mysql_client, index):
+    """
+
+    :param index:
+    :param mysql_client:
+    :param trace_id:
+    :param kimi_title:
+    :param video_id:
+    :return:
+    """
+    response = request_for_info(video_id)
+    productionCover = response['data'][0]['shareImgPath']
+    productionName = kimi_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 = "Web"
+    root_share_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
+    }
+    update_result_sql = f"""
+                    UPDATE long_articles_video_dev
+                    SET
+                        result{index} = '{json.dumps(result, ensure_ascii=False)}',
+                        success = 1
+                    WHERE
+                        trace_id = '{trace_id}'
+                """
+    await mysql_client.async_insert(update_result_sql)
+    logging(
+        code="2000",
+        info="统计 root_share_id && video_id",
+        function="process",
+        trace_id=trace_id,
+        data={
+            "rootShareId": root_share_id,
+            "videoId": video_id
+        }
+    )
+    return result
+
+
 async def recall_videos(trace_id, mysql_client):
 async def recall_videos(trace_id, mysql_client):
     """
     """
     从 mysql 读取数据
     从 mysql 读取数据
     :param trace_id:  唯一 id
     :param trace_id:  唯一 id
-    :param mysql_client: mysql 服务
+    :param mysql_client: mysql 服务
     :return:
     :return:
     """
     """
     select_sql = f"""
     select_sql = f"""
-        SELECT recall_video_id1, kimi_title 
-        FROM long_articles_video
+        SELECT recall_video_id1,recall_video_id2, recall_video_id3, kimi_title 
+        FROM long_articles_video_dev
         WHERE trace_id = '{trace_id}';
         WHERE trace_id = '{trace_id}';
     """
     """
     info_tuple = await mysql_client.async_select(select_sql)
     info_tuple = await mysql_client.async_select(select_sql)
-    best_video_id, kimi_title = info_tuple[0]
-    print(best_video_id)
-    if best_video_id:
-        logging(
-            code="1002",
-            info="best video_id --{}".format(best_video_id),
-            function="process",
-            trace_id=trace_id
-        )
-        print("best video id", best_video_id)
-        response = request_for_info(best_video_id)
-        productionCover = response['data'][0]['shareImgPath']
-        productionName = kimi_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 = "Web"
-        root_share_id, productionPath = create_gzh_path(video_id=best_video_id, shared_uid=user_id)
+    vid1, vid2, vid3, kimi_title = info_tuple[0]
+    vid_list = [vid1, vid2, vid3]
+    unEmptyList = [i for i in vid_list if i]
+    L = []
+    print(unEmptyList)
+    if unEmptyList:
         logging(
         logging(
             code="1002",
             code="1002",
-            info="root_share_id --{}, productionPath -- {}".format(root_share_id, productionPath),
+            info="vid_list: {}".format(json.dumps(unEmptyList, ensure_ascii=False)),
             function="process",
             function="process",
             trace_id=trace_id
             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
-        }
-        update_result_sql = f"""
-            UPDATE long_articles_video
-            SET
-                result1 = '{json.dumps(result, ensure_ascii=False)}',
-                success = 1
-            WHERE
-                trace_id = '{trace_id}'
-        """
-        await mysql_client.async_insert(update_result_sql)
-        logging(
-            code="2000",
-            info="统计 root_share_id && video_id",
-            function="process",
-            trace_id=trace_id,
-            data={
-                "rootShareId": root_share_id,
-                "videoId": best_video_id
-            }
-        )
+        for index, best_video_id in enumerate(unEmptyList, 1):
+            temp = await return_info(
+                video_id=best_video_id,
+                kimi_title=kimi_title,
+                trace_id=trace_id,
+                mysql_client=mysql_client,
+                index=index
+            )
+            L.append(temp)
+
     else:
     else:
-        result = {
+        L = {
             "traceId": trace_id,
             "traceId": trace_id,
             "Message": "No Videos Found now, Please try again in one minute"
             "Message": "No Videos Found now, Please try again in one minute"
         }
         }
@@ -86,7 +111,7 @@ async def recall_videos(trace_id, mysql_client):
         code="1002",
         code="1002",
         info="返回结果",
         info="返回结果",
         function="process",
         function="process",
-        data=result,
+        data=L,
         trace_id=trace_id
         trace_id=trace_id
     )
     )
-    return result
+    return L

+ 72 - 45
applications/schedule/search_schedule.py

@@ -2,6 +2,7 @@
 @author: luojunhui
 @author: luojunhui
 调用接口在微信内搜索视频
 调用接口在微信内搜索视频
 """
 """
+import asyncio
 
 
 from applications.search import *
 from applications.search import *
 from applications.static.config import gh_id_dict
 from applications.static.config import gh_id_dict
@@ -99,7 +100,37 @@ class SearchABTest(object):
         :return:
         :return:
         """
         """
         search_result = await SearchMethod().search_v0(
         search_result = await SearchMethod().search_v0(
-            text=",".join(cls.article_keys),
+            text=",".join(cls.article_keys[0]),
+            trace_id=cls.trace_id
+        )
+        if search_result:
+            return search_result
+        else:
+            return await cls.base_line()
+
+    @classmethod
+    async def ab_3(cls):
+        """
+        使用文本关键词搜索
+        :return:
+        """
+        search_result = await SearchMethod().search_v0(
+            text=",".join(cls.article_keys[1]),
+            trace_id=cls.trace_id
+        )
+        if search_result:
+            return search_result
+        else:
+            return await cls.base_line()
+
+    @classmethod
+    async def ab_4(cls):
+        """
+        使用文本关键词搜索
+        :return:
+        """
+        search_result = await SearchMethod().search_v0(
+            text=",".join(cls.article_keys[3]),
             trace_id=cls.trace_id
             trace_id=cls.trace_id
         )
         )
         if search_result:
         if search_result:
@@ -118,6 +149,7 @@ class SearchMethod(object):
     async def search_v0(cls, text, trace_id):
     async def search_v0(cls, text, trace_id):
         """
         """
         搜索顺序-wx --> baidu --> xigua
         搜索顺序-wx --> baidu --> xigua
+        一共需要返回三条视频
         :return:
         :return:
         """
         """
         wx_result = wx_search(keys=text, sensitive_words=cls.s_words)
         wx_result = wx_search(keys=text, sensitive_words=cls.s_words)
@@ -206,50 +238,45 @@ async def search_videos(kimi_info, trace_id, gh_id, mysql_client):
     """
     """
     kimi_info["trace_id"] = trace_id
     kimi_info["trace_id"] = trace_id
     SearchAB = SearchABTest(info=kimi_info, gh_id=gh_id)
     SearchAB = SearchABTest(info=kimi_info, gh_id=gh_id)
-    # if ab_test_config.get(gh_id):
-    #     test_id = ab_test_config[gh_id]
-    #     if test_id == 0:
-    #         recall_obj = SearchAB.ab_0()
-    #     elif test_id == 1:
-    #         recall_obj = SearchAB.ab_1()
-    #     elif test_id == 2:
-    #         recall_obj = SearchAB.ab_2()
-    #     # elif test_id == 3:
-    #     #     recall_obj = SearchAB.ab_3()
-    #     # elif test_id == 4:
-    #     #     recall_obj = SearchAB.ab_4()
-    #     # elif test_id == 5:
-    #     #     recall_obj = SearchAB.ab_5()
-    #     # elif test_id == 6:
-    #     #     recall_obj = SearchAB.ab_6()
-    #     else:
-    #         recall_obj = {}
-    # else:
-    recall_obj = await SearchAB.ab_1()
-    if recall_obj:
-        platform = recall_obj["platform"]
-        recall_video = recall_obj["result"]
-        if recall_video:
-            logging(
-                code="7002",
-                info="视频搜索成功, 搜索平台为--{}".format(platform),
-                trace_id=trace_id,
-                data=recall_video,
-            )
-            video_id = await video_sender(
-                video_obj=recall_video,
-                user=gh_id_dict.get(gh_id),
-                trace_id=trace_id,
-                platform=platform,
-            )
-            update_id_sql = f"""
-            UPDATE long_articles_video
-            SET
-            recall_video_id1 = {video_id}
-            WHERE
-            trace_id = '{trace_id}'
-            """
-            await mysql_client.async_insert(update_id_sql)
+    recall_obj_1 = await SearchAB.ab_1()
+    await asyncio.sleep(3)
+    recall_obj_2 = await SearchAB.ab_2()
+    await asyncio.sleep(3)
+    recall_obj_3 = await SearchAB.ab_3()
+    recall_list = [recall_obj_1, recall_obj_2, recall_obj_3]
+    un_empty_list = [i for i in recall_list if i]
+    if len(un_empty_list) < 3:
+        await asyncio.sleep(3)
+        recall_obj_4 = await SearchAB.ab_4()
+        un_empty_list.append(recall_obj_4)
+
+    # 逐条下载,逐条写表
+    if un_empty_list:
+        for index, recall_obj in enumerate(un_empty_list, 1):
+            platform = recall_obj["platform"]
+            recall_video = recall_obj["result"]
+            if recall_video:
+                logging(
+                    code="7002",
+                    info="视频搜索成功, 搜索平台为--{}".format(platform),
+                    trace_id=trace_id,
+                    data=recall_video,
+                )
+                video_id = await video_sender(
+                    video_obj=recall_video,
+                    user=gh_id_dict.get(gh_id),
+                    trace_id=trace_id,
+                    platform=platform,
+                )
+                update_id_sql = f"""
+                UPDATE long_articles_video_dev
+                SET
+                recall_video_id{index} = {video_id}
+                WHERE
+                trace_id = '{trace_id}'
+                """
+                print(update_id_sql)
+                await mysql_client.async_insert(update_id_sql)
     else:
     else:
         logging(code="7003", info="视频搜索失败", trace_id=trace_id)
         logging(code="7003", info="视频搜索失败", trace_id=trace_id)
         return None
         return None

+ 7 - 6
dev/test_v2.py

@@ -11,9 +11,10 @@ class Test(object):
     """
     """
     测试
     测试
     """
     """
-    # local_ip_address = "localhost"
+    local_ip_address = "localhost"
+
     # local_ip_address = "192.168.100.31"
     # local_ip_address = "192.168.100.31"
-    local_ip_address = "61.48.133.26"
+    # local_ip_address = "61.48.133.26"
 
 
     @classmethod
     @classmethod
     def ask_question(cls):
     def ask_question(cls):
@@ -79,13 +80,13 @@ class Test(object):
 
 
 
 
 T = Test()
 T = Test()
-result = T.ask_question()
-t_id = result['traceId']
+# result = T.ask_question()
+# t_id = result['traceId']
+t_id = "search-600c20be-1dec-46c4-aeba-6299a8dd02ca-1716521624"
 print(t_id)
 print(t_id)
 while True:
 while True:
     res = T.recall_video(trace_id=t_id)
     res = T.recall_video(trace_id=t_id)
-    if res.get("videoUrl"):
+    if type(res) is list:
         print(json.dumps(res, ensure_ascii=False, indent=4))
         print(json.dumps(res, ensure_ascii=False, indent=4))
         break
         break
     time.sleep(5)
     time.sleep(5)
-