|
@@ -3,123 +3,89 @@
|
|
|
对请求进行操作
|
|
|
"""
|
|
|
import json
|
|
|
-import os
|
|
|
|
|
|
-from applications.match_alg import best_choice
|
|
|
from applications.functions.common import Functions
|
|
|
from applications.functions.log import logging
|
|
|
|
|
|
|
|
|
-class ProcessParams(object):
|
|
|
+async def recall_videos(trace_id, mysql_client):
|
|
|
"""
|
|
|
- Params Analysis
|
|
|
+ 从 mysql 读取数据
|
|
|
+ :param trace_id: 唯一 id
|
|
|
+ :param mysql_client: mysql 服务
|
|
|
+ :return:
|
|
|
"""
|
|
|
-
|
|
|
- def __init__(self, t_id):
|
|
|
- self.trace_id = t_id
|
|
|
-
|
|
|
- def get_params(self, data):
|
|
|
- """
|
|
|
- "accountName": "公众号名称",
|
|
|
- "content": "文章正文",
|
|
|
- "title": "文章标题",
|
|
|
- "cover": "封面链接"
|
|
|
- :param data:
|
|
|
- :return: title
|
|
|
- """
|
|
|
+ select_sql = f"""
|
|
|
+ SELECT recall_video_id1, kimi_title
|
|
|
+ FROM long_articles_video_dev
|
|
|
+ WHERE trace_id = '{trace_id}';
|
|
|
+ """
|
|
|
+ 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="处理请求参数",
|
|
|
- function="get_params",
|
|
|
- trace_id=self.trace_id,
|
|
|
- data=data
|
|
|
- )
|
|
|
- return data
|
|
|
-
|
|
|
- async def deal(self, data):
|
|
|
- """执行代码"""
|
|
|
- params = self.get_params(data)
|
|
|
- title = params['title'].split("@@")[-1]
|
|
|
- kimi_title = params['kimi_title']
|
|
|
- # account_name = params['accountName']
|
|
|
- # ghId = params['ghId']
|
|
|
- video_list = params['videoList']
|
|
|
-
|
|
|
- title_p = os.path.join(os.getcwd(), 'applications', 'static', "titles", "{}.json".format(title))
|
|
|
-
|
|
|
- with open(title_p, encoding="utf-8") as f:
|
|
|
- params_obj = json.loads(f.read())
|
|
|
-
|
|
|
- best_video_id = await best_choice(
|
|
|
- params_obj=params_obj,
|
|
|
- trace_id=self.trace_id,
|
|
|
- search_videos=video_list
|
|
|
+ info="best video_id --{}".format(best_video_id),
|
|
|
+ function="process",
|
|
|
+ trace_id=trace_id
|
|
|
)
|
|
|
+ print("best video id", best_video_id)
|
|
|
+ response = Functions().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 = Functions().create_gzh_path(video_id=best_video_id, shared_uid=user_id)
|
|
|
logging(
|
|
|
code="1002",
|
|
|
- info="best video_id --{}".format(best_video_id),
|
|
|
+ info="root_share_id --{}, productionPath -- {}".format(root_share_id, productionPath),
|
|
|
function="process",
|
|
|
- trace_id=self.trace_id
|
|
|
+ trace_id=trace_id
|
|
|
)
|
|
|
-
|
|
|
- if best_video_id:
|
|
|
- print("best video id", best_video_id)
|
|
|
- response = Functions().request_for_info(best_video_id)
|
|
|
- # print(json.dumps(response, ensure_ascii=False, indent=4))
|
|
|
- productionCover = response['data'][0]['shareImgPath']
|
|
|
- # productionName = response["data"][0]['title']
|
|
|
- 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 = Functions().create_gzh_path(video_id=best_video_id, shared_uid=user_id)
|
|
|
- logging(
|
|
|
- code="1002",
|
|
|
- info="root_share_id --{}, productionPath -- {}".format(root_share_id, productionPath),
|
|
|
- function="process",
|
|
|
- trace_id=self.trace_id
|
|
|
- )
|
|
|
- result = {
|
|
|
- "productionCover": productionCover,
|
|
|
- "productionName": productionName,
|
|
|
- "programAvatar": programAvatar,
|
|
|
- "programId": programId,
|
|
|
- "programName": programName,
|
|
|
- "source": source,
|
|
|
- "rootShareId": root_share_id,
|
|
|
- "productionPath": productionPath,
|
|
|
- "videoUrl": videoUrl
|
|
|
- }
|
|
|
- logging(
|
|
|
- code="2000",
|
|
|
- info="统计 root_share_id && video_id",
|
|
|
- function="process",
|
|
|
- trace_id=self.trace_id,
|
|
|
- data={
|
|
|
- "rootShareId": root_share_id,
|
|
|
- "videoId": best_video_id
|
|
|
- }
|
|
|
- )
|
|
|
- else:
|
|
|
- result = {
|
|
|
- "productionCover": None,
|
|
|
- "productionName": None,
|
|
|
- "programAvatar": None,
|
|
|
- "programId": None,
|
|
|
- "programName": None,
|
|
|
- "source": None,
|
|
|
- "rootShareId": None,
|
|
|
- "productionPath": None,
|
|
|
- "videoUrl": None
|
|
|
- }
|
|
|
+ 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
|
|
|
+ result1 = '{json.dumps(result, ensure_ascii=False)}'
|
|
|
+ WHERE
|
|
|
+ trace_id = '{trace_id}'
|
|
|
+ """
|
|
|
+ await mysql_client.async_insert(update_result_sql)
|
|
|
logging(
|
|
|
- code="1002",
|
|
|
- info="返回结果",
|
|
|
+ code="2000",
|
|
|
+ info="统计 root_share_id && video_id",
|
|
|
function="process",
|
|
|
- data=result,
|
|
|
- trace_id=self.trace_id
|
|
|
+ trace_id=trace_id,
|
|
|
+ data={
|
|
|
+ "rootShareId": root_share_id,
|
|
|
+ "videoId": best_video_id
|
|
|
+ }
|
|
|
)
|
|
|
- return result
|
|
|
+ else:
|
|
|
+ result = {
|
|
|
+ "traceId": trace_id,
|
|
|
+ "Message": "No Videos Found now, Please try again in one minute"
|
|
|
+ }
|
|
|
+ logging(
|
|
|
+ code="1002",
|
|
|
+ info="返回结果",
|
|
|
+ function="process",
|
|
|
+ data=result,
|
|
|
+ trace_id=trace_id
|
|
|
+ )
|
|
|
+ return result
|