|
@@ -19,7 +19,7 @@ import jpush
|
|
|
from boto3.session import Session
|
|
|
from django.views.generic.base import View
|
|
|
from pyfcm import FCMNotification
|
|
|
-
|
|
|
+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 Model.models import UidPushModel, AiService
|
|
@@ -97,10 +97,9 @@ class AiView(View):
|
|
|
file_post_one = request_dict.get('fileOne', None)
|
|
|
file_post_two = request_dict.get('fileTwo', None)
|
|
|
file_post_three = request_dict.get('fileThree', None)
|
|
|
- file_post_four = request_dict.get('fileFour', None)
|
|
|
|
|
|
- file_list = [file_post_one, file_post_two, file_post_three, file_post_four]
|
|
|
- del file_post_one, file_post_two, file_post_three, file_post_four
|
|
|
+ file_list = [file_post_one, file_post_two, file_post_three]
|
|
|
+ del file_post_one, file_post_two, file_post_three
|
|
|
if not all(file_list):
|
|
|
for k, val in enumerate(file_list):
|
|
|
if not val:
|
|
@@ -132,8 +131,8 @@ class AiView(View):
|
|
|
ai_start_time = int(time.time())
|
|
|
client = boto3.client(
|
|
|
'rekognition',
|
|
|
- aws_access_key_id='AKIA2E67UIMD6JD6TN3J',
|
|
|
- aws_secret_access_key='6YaziO3aodyNUeaayaF8pK9BxHp/GvbbtdrOAI83',
|
|
|
+ aws_access_key_id=AWS_ACCESS_KEY_ID[1],
|
|
|
+ aws_secret_access_key=AWS_SECRET_ACCESS_KEY[1],
|
|
|
region_name='us-east-1')
|
|
|
# doc:
|
|
|
rekognition_res = client.detect_labels(
|
|
@@ -336,7 +335,7 @@ class AiView(View):
|
|
|
new_bounding_box_dict['file_0'] = []
|
|
|
new_bounding_box_dict['file_1'] = []
|
|
|
new_bounding_box_dict['file_2'] = []
|
|
|
- new_bounding_box_dict['file_3'] = []
|
|
|
+ # new_bounding_box_dict['file_3'] = []
|
|
|
for k, val in enumerate(boundingBoxList):
|
|
|
boundingBoxTop = merge_image_height * val['Top']
|
|
|
# 找出当前边框属于哪张图片范围
|
|
@@ -365,23 +364,34 @@ class AiView(View):
|
|
|
|
|
|
def upload_s3(self, file_dict, dir_path):
|
|
|
try:
|
|
|
- aws_key = AWS_ACCESS_KEY_ID[0] # 【你的 aws_access_key】
|
|
|
- aws_secret = AWS_SECRET_ACCESS_KEY[0] # 【你的 aws_secret_key】
|
|
|
- session = Session(aws_access_key_id=aws_key,
|
|
|
- aws_secret_access_key=aws_secret,
|
|
|
- region_name="cn-northwest-1")
|
|
|
- s3 = session.resource("s3")
|
|
|
- # client = session.client("s3")
|
|
|
- bucket = "push" # 【你 bucket 的名字】 # 首先需要保.证 s3 上已经存在该存储桶,否则报错
|
|
|
+ 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"
|
|
|
+
|
|
|
for file_path, upload_path in file_dict.items():
|
|
|
|
|
|
- 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')
|
|
|
- return True
|
|
|
+ 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')
|
|
|
+ return True
|
|
|
except Exception as e:
|
|
|
print(repr(e))
|
|
|
return False
|