1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- """
- @author: luojunhui
- """
- from applications.upload import *
- from applications.functions import hash_title
- class PublishDeal(object):
- """
- 自动发布接口处理
- """
- def __init__(self, params):
- self.video_id = None
- self.img_list = None
- self.text = None
- self.title = None
- self.params = params
- def check_params(self):
- """
- check params
- """
- try:
- self.title = self.params['title']
- self.text = self.params['text']
- self.img_list = self.params['img_list']
- self.video_id = self.params['video_id']
- return None
- except Exception as e:
- res = {
- "error": "params error",
- "info": "check your param: {}".format(e)
- }
- return res
- def deal(self):
- """
- 处理请求
- """
- params_error = self.check_params()
- if params_error:
- return params_error
- else:
- h_title = hash_title(self.title)
- img_list = []
- for index, url in enumerate(self.img_list, 1):
- save_path = "temp/{}-{}.png".format(h_title, index)
- local_p = download_image(save_path, url)
- oss_key = upload_to_oss(local_p)
- img_obj = {
- "fileName": save_path.replace("temo/", ""),
- "ossKey": oss_key,
- "type": "image/png",
- "size": 1234
- }
- img_list.append(img_obj)
- res = auto_upload_aigc(title="{}video_id={}".format(self.title, self.video_id), text=self.text, img_list=self.img_list)
- return res
|