123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232 |
- """
- @author: luojunhui
- 对请求进行操作
- """
- import json
- from applications.functions.common import request_for_info, create_gzh_path, create_gzh_path_v2
- from applications.functions.log import logging
- from static.config import db_article
- async def return_info_v2(video_id, trace_id, mysql_client):
- """
- :param mysql_client:
- :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/ssyqsh.png"
- programId = "wx59d9e2c05f00f880"
- 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
- }
- update_result_sql = f"""
- UPDATE {db_article}
- SET
- result1 = %s,
- success = %s
- WHERE
- trace_id = %s;
- """
- await mysql_client.async_insert(
- sql=update_result_sql,
- params=(json.dumps(result, ensure_ascii=False), 1, trace_id)
- )
- 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 result
- async def return_info(video_id, kimi_title, trace_id, mysql_client, index, gh_id):
- """
- :param gh_id: 公众号账号id
- :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']
- if gh_id in ['gh_93e00e187787', 'gh_ac43e43b253b']:
- # 投流的两个账号
- programAvatar = "https://rescdn.yishihui.com/0temp/zfyfyc.jpeg"
- programId = "wxcddf231abd0dabdc"
- programName = "祝福有福有财"
- root_share_id, source_id, productionPath = create_gzh_path_v2(video_id=video_id, shared_uid=user_id)
- else:
- programAvatar = "https://rescdn.yishihui.com/0temp/ssyqsh.png"
- programId = "wx59d9e2c05f00f880"
- programName = "刷刷有趣生活"
- root_share_id, source_id, productionPath = create_gzh_path(video_id=video_id, shared_uid=user_id)
- source = "Web"
- 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": index * 0.25
- }
- update_result_sql = f"""
- UPDATE {db_article}
- SET
- result{index} = %s,
- success = %s
- WHERE
- trace_id = %s;
- """
- await mysql_client.async_insert(
- sql=update_result_sql,
- params=(json.dumps(result, ensure_ascii=False), 1, trace_id)
- )
- logging(
- code="2000",
- info="统计 root_share_id && video_id",
- function="process",
- trace_id=trace_id,
- data={
- "rootShareId": root_share_id,
- "videoId": video_id,
- "sourceId": source_id
- }
- )
- return result
- async def recall_videos(trace_id, mysql_client):
- """
- 从 mysql 读取数据
- :param trace_id: 唯一 id
- :param mysql_client: mysql 服务、
- :return:
- """
- select_sql = f"""
- SELECT gh_id, recall_video_id1, recall_video_id2, recall_video_id3, kimi_title, content_status, process_times
- FROM {db_article}
- WHERE trace_id = '{trace_id}';
- """
- info_tuple = await mysql_client.async_select(select_sql)
- gh_id, vid1, vid2, vid3, kimi_title, content_status, process_times = info_tuple[0]
- vid_list = [vid1, vid2, vid3]
- unEmptyList = [i for i in vid_list if i]
- L = []
- if content_status == 0:
- if process_times > 5:
- result = {
- "traceId": trace_id,
- "code": 0,
- "error": "匹配失败,处理超过五次,文章敏感"
- }
- else:
- result = {
- "traceId": trace_id,
- "code": 0,
- "Message": "该请求还没处理"
- }
- elif content_status == 1:
- result = {
- "traceId": trace_id,
- "code": 1,
- "Message": "该请求正在处理中"
- }
- elif content_status == 2:
- logging(
- code="1002",
- info="vid_list: {}".format(json.dumps(unEmptyList, ensure_ascii=False)),
- function="process",
- trace_id=trace_id
- )
- for index, best_video_id in enumerate(unEmptyList, 1):
- # if kimi_title:
- temp = await return_info(
- video_id=best_video_id,
- kimi_title=kimi_title,
- trace_id=trace_id,
- mysql_client=mysql_client,
- index=index,
- gh_id=gh_id
- )
- L.append(temp)
- # else:
- # temp = await return_info_v2(
- # video_id=best_video_id,
- # trace_id=trace_id,
- # mysql_client=mysql_client
- # )
- # L.append(temp)
- # temp['paragraphPosition'] = 0.5
- # L.append(temp)
- # temp['paragraphPosition'] = 0.75
- # L.append(temp)
- result = {
- "traceId": trace_id,
- "miniprogramList": L
- }
- elif content_status == 3:
- result = {
- "traceId": trace_id,
- "code": 0,
- "error": "匹配失败,处理超过五次,文章敏感"
- }
- else:
- result = {
- "traceId": trace_id,
- "Message": "UnKnow Error"
- }
- logging(
- code="1002",
- info="返回结果",
- function="process",
- data=result,
- trace_id=trace_id
- )
- return result
|