process_schedule.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. """
  2. @author: luojunhui
  3. 对请求进行操作
  4. """
  5. import json
  6. from applications.functions.common import request_for_info, create_gzh_path, create_gzh_path_v2
  7. from applications.functions.log import logging
  8. from 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, gh_id):
  69. """
  70. :param gh_id: 公众号账号id
  71. :param index:
  72. :param mysql_client:
  73. :param trace_id:
  74. :param kimi_title:
  75. :param video_id:
  76. :return:
  77. """
  78. response = request_for_info(video_id)
  79. productionCover = response['data'][0]['shareImgPath']
  80. productionName = kimi_title
  81. videoUrl = response['data'][0]['videoPath']
  82. user_id = response['data'][0]['user']['uid']
  83. if gh_id in ['gh_93e00e187787', 'gh_ac43e43b253b']:
  84. # 投流的两个账号
  85. programAvatar = "https://rescdn.yishihui.com/0temp/zfyfyc.jpeg"
  86. programId = "wxcddf231abd0dabdc"
  87. programName = "祝福有福有财"
  88. root_share_id, source_id, productionPath = create_gzh_path_v2(video_id=video_id, shared_uid=user_id)
  89. else:
  90. programAvatar = "https://rescdn.yishihui.com/0temp/ssyqsh.png"
  91. programId = "wx59d9e2c05f00f880"
  92. programName = "刷刷有趣生活"
  93. root_share_id, source_id, productionPath = create_gzh_path(video_id=video_id, shared_uid=user_id)
  94. source = "Web"
  95. logging(
  96. code="1002",
  97. info="root_share_id --{}, productionPath -- {}".format(root_share_id, productionPath),
  98. function="process",
  99. trace_id=trace_id
  100. )
  101. result = {
  102. "productionCover": productionCover,
  103. "productionName": productionName,
  104. "programAvatar": programAvatar,
  105. "programId": programId,
  106. "programName": programName,
  107. "source": source,
  108. "rootShareId": root_share_id,
  109. "productionPath": productionPath,
  110. "videoUrl": videoUrl,
  111. "paragraphPosition": index * 0.25
  112. }
  113. update_result_sql = f"""
  114. UPDATE {db_article}
  115. SET
  116. result{index} = %s,
  117. success = %s
  118. WHERE
  119. trace_id = %s;
  120. """
  121. await mysql_client.async_insert(
  122. sql=update_result_sql,
  123. params=(json.dumps(result, ensure_ascii=False), 1, trace_id)
  124. )
  125. logging(
  126. code="2000",
  127. info="统计 root_share_id && video_id",
  128. function="process",
  129. trace_id=trace_id,
  130. data={
  131. "rootShareId": root_share_id,
  132. "videoId": video_id,
  133. "sourceId": source_id
  134. }
  135. )
  136. return result
  137. async def recall_videos(trace_id, mysql_client):
  138. """
  139. 从 mysql 读取数据
  140. :param trace_id: 唯一 id
  141. :param mysql_client: mysql 服务、
  142. :return:
  143. """
  144. select_sql = f"""
  145. SELECT gh_id, recall_video_id1, recall_video_id2, recall_video_id3, kimi_title, content_status, process_times
  146. FROM {db_article}
  147. WHERE trace_id = '{trace_id}';
  148. """
  149. info_tuple = await mysql_client.async_select(select_sql)
  150. gh_id, vid1, vid2, vid3, kimi_title, content_status, process_times = info_tuple[0]
  151. vid_list = [vid1, vid2, vid3]
  152. unEmptyList = [i for i in vid_list if i]
  153. L = []
  154. if content_status == 0:
  155. if process_times > 5:
  156. result = {
  157. "traceId": trace_id,
  158. "code": 0,
  159. "error": "匹配失败,处理超过五次,文章敏感"
  160. }
  161. else:
  162. result = {
  163. "traceId": trace_id,
  164. "code": 0,
  165. "Message": "该请求还没处理"
  166. }
  167. elif content_status == 1:
  168. result = {
  169. "traceId": trace_id,
  170. "code": 1,
  171. "Message": "该请求正在处理中"
  172. }
  173. elif content_status == 2:
  174. logging(
  175. code="1002",
  176. info="vid_list: {}".format(json.dumps(unEmptyList, ensure_ascii=False)),
  177. function="process",
  178. trace_id=trace_id
  179. )
  180. for index, best_video_id in enumerate(unEmptyList, 1):
  181. # if kimi_title:
  182. temp = await return_info(
  183. video_id=best_video_id,
  184. kimi_title=kimi_title,
  185. trace_id=trace_id,
  186. mysql_client=mysql_client,
  187. index=index,
  188. gh_id=gh_id
  189. )
  190. L.append(temp)
  191. # else:
  192. # temp = await return_info_v2(
  193. # video_id=best_video_id,
  194. # trace_id=trace_id,
  195. # mysql_client=mysql_client
  196. # )
  197. # L.append(temp)
  198. # temp['paragraphPosition'] = 0.5
  199. # L.append(temp)
  200. # temp['paragraphPosition'] = 0.75
  201. # L.append(temp)
  202. result = {
  203. "traceId": trace_id,
  204. "miniprogramList": L
  205. }
  206. elif content_status == 3:
  207. result = {
  208. "traceId": trace_id,
  209. "code": 0,
  210. "error": "匹配失败,处理超过五次,文章敏感"
  211. }
  212. else:
  213. result = {
  214. "traceId": trace_id,
  215. "Message": "UnKnow Error"
  216. }
  217. logging(
  218. code="1002",
  219. info="返回结果",
  220. function="process",
  221. data=result,
  222. trace_id=trace_id
  223. )
  224. return result