publish_deal.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. """
  2. @author: luojunhui
  3. """
  4. from applications.upload import *
  5. from applications.functions import hash_title
  6. class PublishDeal(object):
  7. """
  8. 自动发布接口处理
  9. """
  10. def __init__(self, params):
  11. self.video_id = None
  12. self.img_list = None
  13. self.text = None
  14. self.title = None
  15. self.params = params
  16. def check_params(self):
  17. """
  18. check params
  19. """
  20. try:
  21. self.title = self.params['title']
  22. self.text = self.params['text']
  23. self.img_list = self.params['img_list']
  24. self.video_id = self.params['video_id']
  25. return None
  26. except Exception as e:
  27. res = {
  28. "error": "params error",
  29. "info": "check your param: {}".format(e)
  30. }
  31. return res
  32. def deal(self):
  33. """
  34. 处理请求
  35. """
  36. params_error = self.check_params()
  37. if params_error:
  38. return params_error
  39. else:
  40. h_title = hash_title(self.title)
  41. img_list = []
  42. for index, url in enumerate(self.img_list, 1):
  43. save_path = "temp/{}-{}.png".format(h_title, index)
  44. local_p = download_image(save_path, url)
  45. oss_key = upload_to_oss(local_p)
  46. img_obj = {
  47. "fileName": save_path.replace("temo/", ""),
  48. "ossKey": oss_key,
  49. "type": "image/png",
  50. "size": 1234
  51. }
  52. img_list.append(img_obj)
  53. res = auto_upload_aigc(title="{}video_id={}".format(self.title, self.video_id), text=self.text, img_list=self.img_list)
  54. return res