process_schedule.py 3.9 KB

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