shareCard_deal.py 2.0 KB

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