""" @author: luojunhui """ from applications.functions import request_for_info, create_gzh_path from applications.config import minigram_info from applications.log import logging class ShareCard(object): """ 生成分享卡片 """ def __init__(self, params): self.gh_id = None self.video_id = None self.params = params def check_params(self): """ params check """ try: self.video_id = self.params['videoId'] self.gh_id = self.params['ghId'] return None except AttributeError as e: response = { "code": 0, "error": "Params Error", "msg": "Params: {} is not correct".format(e) } return response def generateCards(self): """ 生成生成卡片的结果 :return: """ response = request_for_info(video_id=self.video_id)['data'][0] cover = response['shareImgPath'] title = response['title'] video_url = response['videoPath'] user_id = response['user']['uid'] root_share_id, source_id, card_path = create_gzh_path(self.video_id, user_id) logging( code="1002", info="root_share_id --{}, productionPath -- {}".format(root_share_id, card_path), ) cardResponse = { "productionCover": cover, "productionName": title, "productionPath": card_path, "programAvatar": minigram_info['avatar_url'], "programId": minigram_info['mid'], "programName": minigram_info['name'], "rootShareId": root_share_id, "sourceId": source_id, "Source": "PQ", "videoUrl": video_url } return cardResponse def deal(self): """ Deal function :return: """ params_error = self.check_params() if params_error: return params_error else: result = { "videoId": self.video_id, "ghId": self.gh_id, "shareCard": self.generateCards() } return result