shareCard_deal.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. """
  2. @author: luojunhui
  3. """
  4. from applications.functions import request_for_info, create_gzh_path
  5. from applications.config import minigram_info
  6. from applications.log import logging
  7. class ShareCard(object):
  8. """
  9. 生成分享卡片
  10. """
  11. def __init__(self, params):
  12. self.gh_id = None
  13. self.video_id = None
  14. self.params = params
  15. def check_params(self):
  16. """
  17. params check
  18. """
  19. try:
  20. self.video_id = self.params['videoId']
  21. self.gh_id = self.params['ghId']
  22. return None
  23. except AttributeError as e:
  24. response = {
  25. "code": 0,
  26. "error": "Params Error",
  27. "msg": "Params: {} is not correct".format(e)
  28. }
  29. return response
  30. def generateCards(self):
  31. """
  32. 生成生成卡片的结果
  33. :return:
  34. """
  35. response = request_for_info(video_id=self.video_id)['data'][0]
  36. cover = response['shareImgPath']
  37. title = response['title']
  38. video_url = response['videoPath']
  39. user_id = response['user']['uid']
  40. root_share_id, source_id, card_path = create_gzh_path(self.video_id, user_id)
  41. logging(
  42. code="1002",
  43. info="root_share_id --{}, productionPath -- {}".format(root_share_id, card_path),
  44. )
  45. cardResponse = {
  46. "productionCover": cover,
  47. "productionName": title,
  48. "productionPath": card_path,
  49. "programAvatar": minigram_info['avatar_url'],
  50. "programId": minigram_info['mid'],
  51. "programName": minigram_info['name'],
  52. "rootShareId": root_share_id,
  53. "sourceId": source_id,
  54. "Source": "PQ",
  55. "videoUrl": video_url
  56. }
  57. return cardResponse
  58. def deal(self):
  59. """
  60. Deal function
  61. :return:
  62. """
  63. params_error = self.check_params()
  64. if params_error:
  65. return params_error
  66. else:
  67. result = {
  68. "videoId": self.video_id,
  69. "ghId": self.gh_id,
  70. "shareCard": self.generateCards()
  71. }
  72. return result