process_schedule.py 5.1 KB

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