process_schedule.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. }
  44. update_result_sql = f"""
  45. UPDATE long_articles_video_dev
  46. SET
  47. result{index} = '{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 && video_id",
  56. function="process",
  57. trace_id=trace_id,
  58. data={
  59. "rootShareId": root_share_id,
  60. "videoId": video_id
  61. }
  62. )
  63. return result
  64. async def recall_videos(trace_id, mysql_client):
  65. """
  66. 从 mysql 读取数据
  67. :param trace_id: 唯一 id
  68. :param mysql_client: mysql 服务、
  69. :return:
  70. """
  71. select_sql = f"""
  72. SELECT recall_video_id1,recall_video_id2, recall_video_id3, kimi_title
  73. FROM long_articles_video_dev
  74. WHERE trace_id = '{trace_id}';
  75. """
  76. info_tuple = await mysql_client.async_select(select_sql)
  77. vid1, vid2, vid3, kimi_title = info_tuple[0]
  78. vid_list = [vid1, vid2, vid3]
  79. unEmptyList = [i for i in vid_list if i]
  80. L = []
  81. print(unEmptyList)
  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. else:
  99. L = {
  100. "traceId": trace_id,
  101. "Message": "No Videos Found now, Please try again in one minute"
  102. }
  103. logging(
  104. code="1002",
  105. info="返回结果",
  106. function="process",
  107. data=L,
  108. trace_id=trace_id
  109. )
  110. return L