oss_rank.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. """
  2. @author luojunhui
  3. @description: find top fission / read oss path list
  4. """
  5. from applications.const import server_const
  6. from applications.match_algorithm import get_content_id_fission_info
  7. from applications.match_algorithm import get_history_content_ids
  8. class OssRank:
  9. """
  10. input: content_id
  11. output: find the top fission / read oss path list
  12. """
  13. def __init__(self, db_client, params):
  14. self.db_client = db_client
  15. self.params = params
  16. self.content_id = None
  17. async def check_params(self):
  18. """
  19. check params
  20. """
  21. try:
  22. self.content_id = self.params['contentId']
  23. self.video_limit = self.params.get("videoLimit", server_const.VIDEO_LIMIT)
  24. return
  25. except KeyError as e:
  26. result = {
  27. "error": str(e),
  28. "message": "invalid params",
  29. "data": self.params,
  30. "code": server_const.PARAMS_CHECK_FAILED_CODE
  31. }
  32. return result
  33. async def deal(self):
  34. """
  35. entrance of this class
  36. """
  37. params_error = await self.check_params()
  38. if params_error:
  39. return params_error
  40. else:
  41. history_content_tuple = await get_history_content_ids(
  42. content_id=self.content_id,
  43. db_client=self.db_client
  44. )
  45. if history_content_tuple:
  46. oss_path_result = await get_content_id_fission_info(
  47. content_id_tuple=history_content_tuple,
  48. db_client=self.db_client,
  49. video_limit=self.video_limit
  50. )
  51. if oss_path_result:
  52. oss_path_list = [
  53. {
  54. "video_oss_path": i['oss_name'],
  55. "fission_0_on_read": i['fission_0_on_read'],
  56. "uid": server_const.RE_RANK_UID
  57. }
  58. for i in oss_path_result
  59. ]
  60. code = server_const.SUCCESS_CODE
  61. else:
  62. oss_path_list = []
  63. code = server_const.FAIL_CODE
  64. return {
  65. "oss_path_list": oss_path_list,
  66. "code": code
  67. }
  68. else:
  69. return {
  70. "oss_path_list": [],
  71. "code": server_const.FAIL_CODE
  72. }