|
@@ -2,6 +2,7 @@
|
|
|
@author: luojunhui
|
|
|
"""
|
|
|
from applications.upload import *
|
|
|
+from applications.functions import hash_title
|
|
|
|
|
|
|
|
|
class PublishDeal(object):
|
|
@@ -9,5 +10,50 @@ class PublishDeal(object):
|
|
|
自动发布接口处理
|
|
|
"""
|
|
|
def __init__(self, params):
|
|
|
- self.title = params['title']
|
|
|
- self.text = params['text']
|
|
|
+ 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
|
|
|
+
|