process_schedule.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. async def return_info_v2(video_id, trace_id, mysql_client):
  9. """
  10. :param mysql_client:
  11. :param trace_id:
  12. :param video_id:
  13. :return:
  14. """
  15. response = request_for_info(video_id)
  16. productionCover = response['data'][0]['shareImgPath']
  17. productionName = response['data'][0]['title']
  18. videoUrl = response['data'][0]['videoPath']
  19. user_id = response['data'][0]['user']['uid']
  20. programAvatar = "https://rescdn.yishihui.com/0temp/lehuo.png"
  21. programId = "wxe8f8f0e23cecad0f"
  22. programName = "票圈乐活"
  23. source = "PQ"
  24. root_share_id, source_id, productionPath = create_gzh_path(video_id=video_id, shared_uid=user_id)
  25. logging(
  26. code="1002",
  27. info="root_share_id --{}, productionPath -- {}".format(root_share_id, productionPath),
  28. function="process",
  29. trace_id=trace_id
  30. )
  31. result = {
  32. "productionCover": productionCover,
  33. "productionName": productionName,
  34. "programAvatar": programAvatar,
  35. "programId": programId,
  36. "programName": programName,
  37. "source": source,
  38. "rootShareId": root_share_id,
  39. "productionPath": productionPath,
  40. "videoUrl": videoUrl,
  41. "paragraphPosition": 0.25
  42. }
  43. update_result_sql = f"""
  44. UPDATE long_articles_video
  45. SET
  46. result1 = '{json.dumps(result, ensure_ascii=False)}',
  47. success = 1
  48. WHERE
  49. trace_id = '{trace_id}'
  50. """
  51. await mysql_client.async_insert(update_result_sql)
  52. logging(
  53. code="2000",
  54. info="root_share_id和source_id",
  55. function="process",
  56. trace_id=trace_id,
  57. data={
  58. "rootShareId": root_share_id,
  59. "videoId": video_id,
  60. "sourceId": source_id
  61. }
  62. )
  63. return result
  64. async def return_info(video_id, kimi_title, trace_id, mysql_client, index):
  65. """
  66. :param index:
  67. :param mysql_client:
  68. :param trace_id:
  69. :param kimi_title:
  70. :param video_id:
  71. :return:
  72. """
  73. response = request_for_info(video_id)
  74. productionCover = response['data'][0]['shareImgPath']
  75. productionName = kimi_title
  76. videoUrl = response['data'][0]['videoPath']
  77. user_id = response['data'][0]['user']['uid']
  78. programAvatar = "https://rescdn.yishihui.com/0temp/lehuo.png"
  79. programId = "wxe8f8f0e23cecad0f"
  80. programName = "票圈乐活"
  81. source = "Web"
  82. root_share_id, source_id, productionPath = create_gzh_path(video_id=video_id, shared_uid=user_id)
  83. logging(
  84. code="1002",
  85. info="root_share_id --{}, productionPath -- {}".format(root_share_id, productionPath),
  86. function="process",
  87. trace_id=trace_id
  88. )
  89. result = {
  90. "productionCover": productionCover,
  91. "productionName": productionName,
  92. "programAvatar": programAvatar,
  93. "programId": programId,
  94. "programName": programName,
  95. "source": source,
  96. "rootShareId": root_share_id,
  97. "productionPath": productionPath,
  98. "videoUrl": videoUrl,
  99. "paragraphPosition": index * 0.25
  100. }
  101. update_result_sql = f"""
  102. UPDATE long_articles_video
  103. SET
  104. result{index} = '{json.dumps(result, ensure_ascii=False)}',
  105. success = 1
  106. WHERE
  107. trace_id = '{trace_id}'
  108. """
  109. await mysql_client.async_insert(update_result_sql)
  110. logging(
  111. code="2000",
  112. info="统计 root_share_id && video_id",
  113. function="process",
  114. trace_id=trace_id,
  115. data={
  116. "rootShareId": root_share_id,
  117. "videoId": video_id,
  118. "sourceId": source_id
  119. }
  120. )
  121. return result
  122. async def recall_videos(trace_id, mysql_client):
  123. """
  124. 从 mysql 读取数据
  125. :param trace_id: 唯一 id
  126. :param mysql_client: mysql 服务、
  127. :return:
  128. """
  129. select_sql = f"""
  130. SELECT recall_video_id1, recall_video_id2, recall_video_id3, kimi_title
  131. FROM long_articles_video
  132. WHERE trace_id = '{trace_id}';
  133. """
  134. info_tuple = await mysql_client.async_select(select_sql)
  135. vid1, vid2, vid3, kimi_title = info_tuple[0]
  136. vid_list = [vid1, vid2, vid3]
  137. unEmptyList = [i for i in vid_list if i]
  138. L = []
  139. if unEmptyList:
  140. logging(
  141. code="1002",
  142. info="vid_list: {}".format(json.dumps(unEmptyList, ensure_ascii=False)),
  143. function="process",
  144. trace_id=trace_id
  145. )
  146. for index, best_video_id in enumerate(unEmptyList, 1):
  147. if kimi_title:
  148. temp = await return_info(
  149. video_id=best_video_id,
  150. kimi_title=kimi_title,
  151. trace_id=trace_id,
  152. mysql_client=mysql_client,
  153. index=index
  154. )
  155. else:
  156. temp = await return_info_v2(
  157. video_id=best_video_id,
  158. trace_id=trace_id,
  159. mysql_client=mysql_client
  160. )
  161. L.append(temp)
  162. result = {
  163. "traceId": trace_id,
  164. "miniprogramList": L
  165. }
  166. else:
  167. result = {
  168. "traceId": trace_id,
  169. "Message": "No Videos Found now, Please try again in one minute"
  170. }
  171. logging(
  172. code="1002",
  173. info="返回结果",
  174. function="process",
  175. data=result,
  176. trace_id=trace_id
  177. )
  178. return result