process_schedule.py 5.9 KB

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