|
@@ -13,9 +13,8 @@ from django.views.generic.base import View
|
|
|
from pyfcm import FCMNotification
|
|
|
|
|
|
from AnsjerPush.Config.aiConfig import LABEL_DICT, AI_IDENTIFICATION_TAGS_DICT
|
|
|
-from AnsjerPush.config import SERVER_TYPE
|
|
|
-from AnsjerPush.config import AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, APNS_MODE, APNS_CONFIG, BASE_DIR, \
|
|
|
- JPUSH_CONFIG, FCM_CONFIG
|
|
|
+from AnsjerPush.config import APNS_MODE, APNS_CONFIG, BASE_DIR, \
|
|
|
+ JPUSH_CONFIG, FCM_CONFIG, ACCESS_KEY_ID, SECRET_ACCESS_KEY, REGION_NAME, PUSH_BUCKET
|
|
|
from Model.models import UidPushModel, AiService
|
|
|
from Object.ETkObject import ETkObject
|
|
|
from Object.MergePic import ImageProcessing
|
|
@@ -138,9 +137,10 @@ class AiView(View):
|
|
|
file_dict = {}
|
|
|
for i, val in enumerate(file_path_list):
|
|
|
# 封面图
|
|
|
- file_dict[val] = "{}/{}/{}_{}.jpeg".format(uid, channel, n_time, i)
|
|
|
- thread_task = threading.Thread(target=self.upload_s3, args=(file_dict, dir_path))
|
|
|
- thread_task.start()
|
|
|
+ file_dict[val] = '{}/{}/{}_{}.jpeg'.format(uid, channel, n_time, i)
|
|
|
+ upload_images_thread = threading.Thread(target=self.upload_images, args=(file_dict, dir_path))
|
|
|
+ upload_images_thread.start()
|
|
|
+
|
|
|
# 存储消息以及推送
|
|
|
is_st = 3 # 多图
|
|
|
# 查询推送数据
|
|
@@ -330,52 +330,28 @@ class AiView(View):
|
|
|
logger.info('------label_dict------ {}'.format(label_dict))
|
|
|
return label_dict
|
|
|
|
|
|
- def del_path(self, path):
|
|
|
- if not os.path.exists(path):
|
|
|
- return
|
|
|
- if os.path.isfile(path):
|
|
|
- os.remove(path)
|
|
|
- else:
|
|
|
- items = os.listdir(path)
|
|
|
- for f in items:
|
|
|
- c_path = os.path.join(path, f)
|
|
|
- if os.path.isdir(c_path):
|
|
|
- self.del_path(c_path)
|
|
|
- else:
|
|
|
- os.remove(c_path)
|
|
|
- os.rmdir(path)
|
|
|
-
|
|
|
- def upload_s3(self, file_dict, dir_path):
|
|
|
+ @staticmethod
|
|
|
+ def upload_images(file_dict, dir_path):
|
|
|
+ """
|
|
|
+ 上传图片
|
|
|
+ @param file_dict: S3图片路径
|
|
|
+ @param dir_path: 本地图片路径
|
|
|
+ @return: boolean
|
|
|
+ """
|
|
|
try:
|
|
|
- if SERVER_TYPE == "Ansjer.formal_settings":
|
|
|
- #存国外
|
|
|
- aws_key = AWS_ACCESS_KEY_ID[1]
|
|
|
- aws_secret = AWS_SECRET_ACCESS_KEY[1]
|
|
|
- session = Session(aws_access_key_id=aws_key,
|
|
|
- aws_secret_access_key=aws_secret,
|
|
|
- region_name="us-east-1")
|
|
|
- s3 = session.resource("s3")
|
|
|
- bucket = "foreignpush"
|
|
|
- else:
|
|
|
- #存国内
|
|
|
- aws_key = AWS_ACCESS_KEY_ID[0]
|
|
|
- aws_secret = AWS_SECRET_ACCESS_KEY[0]
|
|
|
- session = Session(aws_access_key_id=aws_key,
|
|
|
- aws_secret_access_key=aws_secret,
|
|
|
- region_name="cn-northwest-1")
|
|
|
- s3 = session.resource("s3")
|
|
|
- bucket = "push"
|
|
|
+ s3 = Session(
|
|
|
+ aws_access_key_id=ACCESS_KEY_ID,
|
|
|
+ aws_secret_access_key=SECRET_ACCESS_KEY,
|
|
|
+ region_name=REGION_NAME
|
|
|
+ ).resource('s3')
|
|
|
|
|
|
for file_path, upload_path in file_dict.items():
|
|
|
- print('-------')
|
|
|
- print(file_path)
|
|
|
- print('-------')
|
|
|
- upload_data = open(file_path, "rb")
|
|
|
- # upload_key = "test"
|
|
|
- s3.Bucket(bucket).put_object(Key=upload_path, Body=upload_data)
|
|
|
- # 需要删除图片
|
|
|
- self.del_path(dir_path)
|
|
|
- self.del_path(dir_path + '.jpg')
|
|
|
+ upload_data = open(file_path, 'rb')
|
|
|
+ s3.Bucket(PUSH_BUCKET).put_object(Key=upload_path, Body=upload_data)
|
|
|
+
|
|
|
+ # 删除图片
|
|
|
+ CommonService.del_path(dir_path)
|
|
|
+ CommonService.del_path(dir_path + '.jpg')
|
|
|
return True
|
|
|
except Exception as e:
|
|
|
print(repr(e))
|