ai_auto_create_creative_job.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. from utils.DataSearchUtils import MysqlSearchUtils
  2. from utils import ResultDictUtils
  3. import datetime
  4. import time
  5. from utils.DateUtils import DateUtils
  6. mysqlUtils = MysqlSearchUtils()
  7. dateUtils = DateUtils()
  8. class AiAutoCreateCreativeJob():
  9. def auto_create_job(self,account_id):
  10. response_dict = ResultDictUtils.common_success_dict
  11. # 查询需要自动创建创意的模板信息
  12. templates = mysqlUtils.get_all_ai_account_target_template_by_params(1,account_id)
  13. if len(templates):
  14. for item in templates:
  15. self.create_creative(item)
  16. return response_dict
  17. else:
  18. return ResultDictUtils.ai_account_template_not_exist_dict
  19. def create_creative(self,item):
  20. # 查询当前时间段内的视频数据
  21. accountId= item["account_id"]
  22. timestamp = time.time()
  23. enddate= dateUtils.get_datetime_str_add_sencend(timestamp,-5*60)
  24. startdate= dateUtils.get_datetime_str_add_sencend(timestamp,-10*60)
  25. list = mysqlUtils.get_kuaishou_video_list_by_params(accountId,startdate,enddate)
  26. if len(list):
  27. return None
  28. else:
  29. return ResultDictUtils.ai_account_template_not_exist_dict
  30. if __name__ == '__main__':
  31. timestamp = time.time()
  32. endtimestamp = timestamp - 5*60
  33. datetime_struct = datetime.datetime.fromtimestamp(timestamp)
  34. enddatetime_struct = datetime.datetime.fromtimestamp(endtimestamp)
  35. print(timestamp)
  36. print(datetime_struct.strftime('%Y-%m-%d %H:%M:%S'))
  37. print(endtimestamp)
  38. print(enddatetime_struct.strftime('%Y-%m-%d %H:%M:%S'))