process_schedule.py 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. """
  2. @author: luojunhui
  3. 对请求进行操作
  4. """
  5. import json
  6. import time
  7. import os
  8. from applications.match_alg import best_choice
  9. from applications.functions.common import Functions
  10. from applications.functions.log import logging
  11. class ProcessParams(object):
  12. """
  13. Params Analysis
  14. """
  15. def __init__(self, t_id):
  16. self.trace_id = t_id
  17. def get_params(self, data):
  18. """
  19. "accountName": "公众号名称",
  20. "content": "文章正文",
  21. "title": "文章标题",
  22. "cover": "封面链接"
  23. :param data:
  24. :return: title
  25. """
  26. logging(
  27. code="1002",
  28. info="处理请求参数",
  29. function="get_params",
  30. trace_id=self.trace_id,
  31. data=data
  32. )
  33. return data
  34. async def deal(self, data):
  35. """执行代码"""
  36. params = self.get_params(data)
  37. title = params['title']
  38. kimi_title = params['kimi_title']
  39. # account_name = params['accountName']
  40. # ghId = params['ghId']
  41. video_list = params['videoList']
  42. title_p = os.path.join(os.getcwd(), 'applications', 'static', "titles", "{}.json".format(title))
  43. with open(title_p, encoding="utf-8") as f:
  44. params_obj = json.loads(f.read())
  45. best_video_id = await best_choice(
  46. params_obj=params_obj,
  47. trace_id=self.trace_id,
  48. search_videos=video_list
  49. )
  50. logging(
  51. code="1002",
  52. info="best video_id --{}".format(best_video_id),
  53. function="process",
  54. trace_id=self.trace_id
  55. )
  56. if best_video_id:
  57. print(best_video_id)
  58. response = Functions().request_for_info(best_video_id)
  59. productionCover = response['data'][0]['shareImgPath']
  60. # productionName = response["data"][0]['title']
  61. productionName = kimi_title
  62. videoUrl = response['data'][0]['videoPath']
  63. user_id = response['data'][0]['user']['uid']
  64. programAvatar = "/static/logo.png"
  65. programId = "wx0b7d95eb293b783b"
  66. programName = "天天美好祝福好生活"
  67. source = "Web"
  68. root_share_id, productionPath = Functions().create_gzh_path(video_id=best_video_id, shared_uid=user_id)
  69. logging(
  70. code="1002",
  71. info="root_share_id --{}, productionPath -- {}".format(root_share_id, productionPath),
  72. function="process",
  73. trace_id=self.trace_id
  74. )
  75. result = {
  76. "productionCover": productionCover,
  77. "productionName": productionName,
  78. "programAvatar": programAvatar,
  79. "programId": programId,
  80. "programName": programName,
  81. "source": source,
  82. "rootShareId": root_share_id,
  83. "productionPath": productionPath,
  84. "videoUrl": videoUrl
  85. }
  86. logging(
  87. code="2000",
  88. info="统计 root_share_id && video_id",
  89. function="process",
  90. trace_id=self.trace_id,
  91. data={
  92. "rootShareId": root_share_id,
  93. "videoId": best_video_id
  94. }
  95. )
  96. else:
  97. result = {
  98. "productionCover": None,
  99. "productionName": None,
  100. "programAvatar": None,
  101. "programId": None,
  102. "programName": None,
  103. "source": None,
  104. "rootShareId": None,
  105. "productionPath": None,
  106. "videoUrl": None
  107. }
  108. logging(
  109. code="1002",
  110. info="返回结果",
  111. function="process",
  112. data=result,
  113. trace_id=self.trace_id
  114. )
  115. return result