process_schedule.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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, source_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. "sourceId": source_id
  63. }
  64. )
  65. return result
  66. async def recall_videos(trace_id, mysql_client):
  67. """
  68. 从 mysql 读取数据
  69. :param trace_id: 唯一 id
  70. :param mysql_client: mysql 服务、
  71. :return:
  72. """
  73. select_sql = f"""
  74. SELECT recall_video_id1,recall_video_id2, recall_video_id3, kimi_title
  75. FROM long_articles_video
  76. WHERE trace_id = '{trace_id}';
  77. """
  78. info_tuple = await mysql_client.async_select(select_sql)
  79. vid1, vid2, vid3, kimi_title = info_tuple[0]
  80. vid_list = [vid1, vid2, vid3]
  81. unEmptyList = [i for i in vid_list if i]
  82. L = []
  83. if unEmptyList:
  84. logging(
  85. code="1002",
  86. info="vid_list: {}".format(json.dumps(unEmptyList, ensure_ascii=False)),
  87. function="process",
  88. trace_id=trace_id
  89. )
  90. for index, best_video_id in enumerate(unEmptyList, 1):
  91. temp = await return_info(
  92. video_id=best_video_id,
  93. kimi_title=kimi_title,
  94. trace_id=trace_id,
  95. mysql_client=mysql_client,
  96. index=index
  97. )
  98. L.append(temp)
  99. result = {
  100. "traceId": trace_id,
  101. "miniprogramList": L
  102. }
  103. else:
  104. result = {
  105. "traceId": trace_id,
  106. "Message": "No Videos Found now, Please try again in one minute"
  107. }
  108. logging(
  109. code="1002",
  110. info="返回结果",
  111. function="process",
  112. data=result,
  113. trace_id=trace_id
  114. )
  115. return result