process_schedule.py 3.5 KB

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