process_schedule.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. # print(json.dumps(response, ensure_ascii=False, indent=4))
  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 = "https://rescdn.yishihui.com/0temp/lehuo.png"
  65. programId = "wxe8f8f0e23cecad0f"
  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