process_schedule.py 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. """
  2. @author: luojunhui
  3. 对请求进行操作
  4. """
  5. import json
  6. from applications.functions.common import request_for_info, create_gzh_path
  7. from applications.functions.log import logging
  8. from applications.static.config import db_article
  9. async def return_info_v2(video_id, trace_id, mysql_client):
  10. """
  11. :param mysql_client:
  12. :param trace_id:
  13. :param video_id:
  14. :return:
  15. """
  16. response = request_for_info(video_id)
  17. productionCover = response['data'][0]['shareImgPath']
  18. productionName = response['data'][0]['title']
  19. videoUrl = response['data'][0]['videoPath']
  20. user_id = response['data'][0]['user']['uid']
  21. programAvatar = "https://rescdn.yishihui.com/0temp/ssyqsh.png"
  22. programId = "wx59d9e2c05f00f880"
  23. programName = "刷刷有趣生活"
  24. source = "PQ"
  25. root_share_id, source_id, productionPath = create_gzh_path(video_id=video_id, shared_uid=user_id)
  26. logging(
  27. code="1002",
  28. info="root_share_id --{}, productionPath -- {}".format(root_share_id, productionPath),
  29. function="process",
  30. trace_id=trace_id
  31. )
  32. result = {
  33. "productionCover": productionCover,
  34. "productionName": productionName,
  35. "programAvatar": programAvatar,
  36. "programId": programId,
  37. "programName": programName,
  38. "source": source,
  39. "rootShareId": root_share_id,
  40. "productionPath": productionPath,
  41. "videoUrl": videoUrl,
  42. "paragraphPosition": 0.25
  43. }
  44. update_result_sql = f"""
  45. UPDATE {db_article}
  46. SET
  47. result1 = %s,
  48. success = %s
  49. WHERE
  50. trace_id = %s;
  51. """
  52. await mysql_client.async_insert(
  53. sql=update_result_sql,
  54. params=(json.dumps(result, ensure_ascii=False), 1, trace_id)
  55. )
  56. logging(
  57. code="2000",
  58. info="root_share_id和source_id",
  59. function="process",
  60. trace_id=trace_id,
  61. data={
  62. "rootShareId": root_share_id,
  63. "videoId": video_id,
  64. "sourceId": source_id
  65. }
  66. )
  67. return result
  68. async def return_info(video_id, kimi_title, trace_id, mysql_client, index):
  69. """
  70. :param index:
  71. :param mysql_client:
  72. :param trace_id:
  73. :param kimi_title:
  74. :param video_id:
  75. :return:
  76. """
  77. response = request_for_info(video_id)
  78. productionCover = response['data'][0]['shareImgPath']
  79. productionName = kimi_title
  80. videoUrl = response['data'][0]['videoPath']
  81. user_id = response['data'][0]['user']['uid']
  82. programAvatar = "https://rescdn.yishihui.com/0temp/ssyqsh.png"
  83. programId = "wx59d9e2c05f00f880"
  84. programName = "刷刷有趣生活"
  85. source = "Web"
  86. root_share_id, source_id, productionPath = create_gzh_path(video_id=video_id, shared_uid=user_id)
  87. logging(
  88. code="1002",
  89. info="root_share_id --{}, productionPath -- {}".format(root_share_id, productionPath),
  90. function="process",
  91. trace_id=trace_id
  92. )
  93. result = {
  94. "productionCover": productionCover,
  95. "productionName": productionName,
  96. "programAvatar": programAvatar,
  97. "programId": programId,
  98. "programName": programName,
  99. "source": source,
  100. "rootShareId": root_share_id,
  101. "productionPath": productionPath,
  102. "videoUrl": videoUrl,
  103. "paragraphPosition": index * 0.25
  104. }
  105. update_result_sql = f"""
  106. UPDATE {db_article}
  107. SET
  108. result{index} = %s,
  109. success = %s
  110. WHERE
  111. trace_id = %s;
  112. """
  113. await mysql_client.async_insert(
  114. sql=update_result_sql,
  115. params=(json.dumps(result, ensure_ascii=False), 1, trace_id)
  116. )
  117. logging(
  118. code="2000",
  119. info="统计 root_share_id && video_id",
  120. function="process",
  121. trace_id=trace_id,
  122. data={
  123. "rootShareId": root_share_id,
  124. "videoId": video_id,
  125. "sourceId": source_id
  126. }
  127. )
  128. return result
  129. async def recall_videos(trace_id, mysql_client):
  130. """
  131. 从 mysql 读取数据
  132. :param trace_id: 唯一 id
  133. :param mysql_client: mysql 服务、
  134. :return:
  135. """
  136. select_sql = f"""
  137. SELECT recall_video_id1, recall_video_id2, recall_video_id3, kimi_title, content_status, process_times
  138. FROM {db_article}
  139. WHERE trace_id = '{trace_id}';
  140. """
  141. info_tuple = await mysql_client.async_select(select_sql)
  142. vid1, vid2, vid3, kimi_title, content_status, process_times = info_tuple[0]
  143. vid_list = [vid1, vid2, vid3]
  144. unEmptyList = [i for i in vid_list if i]
  145. L = []
  146. if content_status == 0:
  147. if process_times > 5:
  148. result = {
  149. "traceId": trace_id,
  150. "code": 0,
  151. "error": "匹配失败,检查原因"
  152. }
  153. else:
  154. result = {
  155. "traceId": trace_id,
  156. "code": 0,
  157. "Message": "该请求还没处理"
  158. }
  159. elif content_status == 1:
  160. result = {
  161. "traceId": trace_id,
  162. "code": 1,
  163. "Message": "该请求正在处理中"
  164. }
  165. elif content_status == 2:
  166. logging(
  167. code="1002",
  168. info="vid_list: {}".format(json.dumps(unEmptyList, ensure_ascii=False)),
  169. function="process",
  170. trace_id=trace_id
  171. )
  172. for index, best_video_id in enumerate(unEmptyList, 1):
  173. if kimi_title:
  174. temp = await return_info(
  175. video_id=best_video_id,
  176. kimi_title=kimi_title,
  177. trace_id=trace_id,
  178. mysql_client=mysql_client,
  179. index=index
  180. )
  181. L.append(temp)
  182. else:
  183. temp = await return_info_v2(
  184. video_id=best_video_id,
  185. trace_id=trace_id,
  186. mysql_client=mysql_client
  187. )
  188. L.append(temp)
  189. temp['paragraphPosition'] = 0.5
  190. L.append(temp)
  191. temp['paragraphPosition'] = 0.75
  192. L.append(temp)
  193. result = {
  194. "traceId": trace_id,
  195. "miniprogramList": L
  196. }
  197. elif content_status == 3:
  198. result = {
  199. "traceId": trace_id,
  200. "code": 0,
  201. "error": "匹配失败,检查原因"
  202. }
  203. else:
  204. result = {
  205. "traceId": trace_id,
  206. "Message": "UnKnow Error"
  207. }
  208. logging(
  209. code="1002",
  210. info="返回结果",
  211. function="process",
  212. data=result,
  213. trace_id=trace_id
  214. )
  215. return result