update edge
This commit is contained in:
@ -89,7 +89,7 @@ def search():
|
|||||||
print('result >>>>> {}'.format(result))
|
print('result >>>>> {}'.format(result))
|
||||||
return result
|
return result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print('result >>>>> {}'.format(result))
|
print('Exception >>>>> {}'.format(result))
|
||||||
return result
|
return result
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(e) #异常返回00
|
logger.warning(e) #异常返回00
|
||||||
|
@ -61,3 +61,19 @@ _C.riskControl = 'http://api.test2.ieemoo.com/emoo-api/riskControl/shoporder/che
|
|||||||
_C.Ocrimg = '../module/ieemoo-ai-assist/imgs'#post ocr img
|
_C.Ocrimg = '../module/ieemoo-ai-assist/imgs'#post ocr img
|
||||||
_C.Ocrtxt = '../module/ieemoo-ai-assist/document'#post ocr txts
|
_C.Ocrtxt = '../module/ieemoo-ai-assist/document'#post ocr txts
|
||||||
_C.Ocrvideo = '../module/ieemoo-ai-assist/videos'#post ocr video
|
_C.Ocrvideo = '../module/ieemoo-ai-assist/videos'#post ocr video
|
||||||
|
|
||||||
|
#obs
|
||||||
|
_C.obs_access_key_id='LHXJC7GIC2NNUUHHTNVI'
|
||||||
|
_C.obs_secret_access_key='sVWvEItrFKWPp5DxeMvX8jLFU69iXPpzkjuMX3iM'
|
||||||
|
_C.obs_server='https://obs.cn-east-3.myhuaweicloud.com'
|
||||||
|
_C.obs_bucketName = 'ieemoo-ai'
|
||||||
|
|
||||||
|
#cos
|
||||||
|
_C.cos_secret_id = 'AKIDIVcVFnBMMLCqbFF6lPr6930tc8VlrlS0'
|
||||||
|
_C.cos_secret_key = 'oYGrJG2d3LTUPBoFTZVEmC1kQ1ObdTkr'
|
||||||
|
_C.cos_region = 'ap-shanghai'
|
||||||
|
_C.cos_Bucket = 'ieemoo-ai-1321281601'
|
||||||
|
|
||||||
|
#cos or obs
|
||||||
|
_C.cos = True
|
||||||
|
_C.obs = True
|
||||||
|
46
utils/up_load_file.py
Normal file
46
utils/up_load_file.py
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
from obs import ObsClient
|
||||||
|
import obs
|
||||||
|
from utils.config import cfg
|
||||||
|
from qcloud_cos import CosConfig,CosS3Client
|
||||||
|
from qcloud_cos.cos_exception import CosClientError, CosServiceError
|
||||||
|
|
||||||
|
def obsInit():
|
||||||
|
print('start init obs <<')
|
||||||
|
obsClient = ObsClient(
|
||||||
|
access_key_id=cfg.obs_access_key_id,
|
||||||
|
secret_access_key=cfg.obs_secret_access_key,
|
||||||
|
server=cfg.obs_server)
|
||||||
|
bucketName = cfg.obs_bucketName
|
||||||
|
headers = obs.SetObjectMetadataHeader()
|
||||||
|
headers.cacheControl = "no-cache"
|
||||||
|
return obsClient, headers
|
||||||
|
|
||||||
|
def cosInit():
|
||||||
|
print('start init cos <<')
|
||||||
|
secret_id = cfg.cos_secret_id
|
||||||
|
secret_key = cfg.cos_secret_key
|
||||||
|
region = cfg.cos_region
|
||||||
|
config = CosConfig(Region=region, Secret_id=secret_id, Secret_key=secret_key)
|
||||||
|
client = CosS3Client(config)
|
||||||
|
return client
|
||||||
|
|
||||||
|
class up_load:
|
||||||
|
def __init__(self):
|
||||||
|
self.cosclient = cosInit()
|
||||||
|
self.obsclient, self.headers = obsInit()
|
||||||
|
|
||||||
|
def upLoad(self, key=None, datapath=None):
|
||||||
|
# 使用高级接口断点续传,失败重试时不会上传已成功的分块(这里重试10次)
|
||||||
|
if cfg.cos:
|
||||||
|
for i in range(0, 10):
|
||||||
|
try:
|
||||||
|
response = self.cosclient.upload_file(
|
||||||
|
Bucket=cfg.cos_Bucket,
|
||||||
|
Key=key,
|
||||||
|
LocalFilePath=datapath)
|
||||||
|
break
|
||||||
|
except CosClientError or CosServiceError as e:
|
||||||
|
print(e)
|
||||||
|
if cfg.obs:
|
||||||
|
response = self.obsclient.putFile(cfg.obs_bucketName, key, datapath)
|
||||||
|
return response
|
@ -2,22 +2,15 @@ from obs import ObsClient
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
#from config import cfg
|
#from config import cfg
|
||||||
from utils.config import cfg
|
from utils.config import cfg
|
||||||
import os,threading
|
import os, sys
|
||||||
import time as ti
|
import time as ti
|
||||||
import base64,requests,cv2,shutil
|
import base64,requests,cv2,shutil
|
||||||
lock = threading.Lock()
|
from utils.up_load_file import up_load
|
||||||
obsClient = ObsClient(
|
|
||||||
access_key_id='LHXJC7GIC2NNUUHHTNVI',
|
|
||||||
secret_access_key='sVWvEItrFKWPp5DxeMvX8jLFU69iXPpzkjuMX3iM',
|
|
||||||
server='https://obs.cn-east-3.myhuaweicloud.com'
|
|
||||||
)
|
|
||||||
bucketName = 'ieemoo-ai'
|
|
||||||
|
|
||||||
|
up_load_data = up_load()
|
||||||
def AddObs(file_path, status):
|
def AddObs(file_path, status):
|
||||||
#with lock:
|
|
||||||
if not cfg.flag:
|
if not cfg.flag:
|
||||||
addobs(file_path, status)
|
addobs(file_path, status)
|
||||||
#os.remove(file_path)
|
|
||||||
else:
|
else:
|
||||||
if status == '02':
|
if status == '02':
|
||||||
addobs(file_path, status)
|
addobs(file_path, status)
|
||||||
@ -42,19 +35,13 @@ def addobs(file_path, status): #save videos
|
|||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
if not 'data' in status:
|
if not 'data' in status:
|
||||||
# os.remove(file_path)
|
|
||||||
return 'can not get the status'
|
return 'can not get the status'
|
||||||
status = status['data']
|
status = status['data']
|
||||||
objectkey = os.path.basename(file_path)
|
objectkey = os.path.basename(file_path)
|
||||||
status_ = get_weightStatus(objectkey)
|
|
||||||
# backups_path = os.sep.join([cfg.backups, status+'_'+objectkey])
|
|
||||||
time = os.path.basename(file_path).split('-')[0]
|
time = os.path.basename(file_path).split('-')[0]
|
||||||
if objectkey.split('.')[-1] in ['avi','mp4']:
|
|
||||||
objectkey = 'videos/'+time+'/'+status+'/'+status+'_'+objectkey
|
objectkey = 'videos/'+time+'/'+status+'/'+status+'_'+objectkey
|
||||||
if status == '02' or status_:
|
if status == '02' or get_weightStatus(objectkey):
|
||||||
resp = obsClient.putFile(bucketName, objectkey, file_path)
|
up_load_data.upLoad(objectkey, file_path)
|
||||||
# shutil.move(file_path, backups_path)
|
|
||||||
#os.remove(file_path)
|
|
||||||
|
|
||||||
def Addimg(uuid_barcode):
|
def Addimg(uuid_barcode):
|
||||||
time = uuid_barcode.split('-')[0].split('_')[-1]
|
time = uuid_barcode.split('-')[0].split('_')[-1]
|
||||||
@ -64,20 +51,24 @@ def Addimg(uuid_barcode):
|
|||||||
file_path = os.sep.join([cfg.Tempimg, '3_'+uuid_barcode+'.jpg'])
|
file_path = os.sep.join([cfg.Tempimg, '3_'+uuid_barcode+'.jpg'])
|
||||||
if not os.path.exists(file_path):
|
if not os.path.exists(file_path):
|
||||||
file_path = os.sep.join([cfg.Tempimg, 'ex_'+uuid_barcode+'.jpg'])
|
file_path = os.sep.join([cfg.Tempimg, 'ex_'+uuid_barcode+'.jpg'])
|
||||||
resp = obsClient.putFile(bucketName, objectkey, file_path)
|
uuid = uuid_barcode.split('_')[-1]
|
||||||
|
if get_weightStatus(uuid):
|
||||||
|
up_load_data.upLoad(objectkey, file_path)
|
||||||
|
|
||||||
def Addimg_content(uuid_barcode, context):
|
def Addimg_content(uuid_barcode, context):
|
||||||
|
file_path = "context.jpg"
|
||||||
|
cv2.imwrite(file_path, context)
|
||||||
success, encoded_image = cv2.imencode(".jpg",context)
|
success, encoded_image = cv2.imencode(".jpg",context)
|
||||||
context = encoded_image.tobytes()
|
context = encoded_image.tobytes()
|
||||||
time = uuid_barcode.split('-')[0]
|
time = uuid_barcode.split('-')[0]
|
||||||
objectkey = 'imgs/'+time+'/'+uuid_barcode+'.jpg'
|
objectkey = 'imgs/'+time+'/'+uuid_barcode+'.jpg'
|
||||||
resp = obsClient.putContent(bucketName, objectkey, context)
|
if get_weightStatus(uuid_barcode):
|
||||||
|
up_load_data.upLoad(objectkey, file_path)
|
||||||
|
|
||||||
def get_weightStatus(uuid):
|
def get_weightStatus(uuid):
|
||||||
uuid = uuid.split('_')[1]
|
uuid = uuid.split('_')[1]
|
||||||
resp = requests.post(url = cfg.riskControl)
|
resp = requests.post(url = cfg.riskControl)
|
||||||
up_uuid = resp.json()['data']
|
up_uuid = resp.json()['data']
|
||||||
#print('>>>>>>>>>>>>>',up_uuid)
|
|
||||||
if uuid in up_uuid:
|
if uuid in up_uuid:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
Reference in New Issue
Block a user