process.py 3.7 KB

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