update edge

This commit is contained in:
2023-11-23 15:11:14 +08:00
parent 926f9d3768
commit 0fb07b84a7
4 changed files with 76 additions and 23 deletions

View File

@ -89,7 +89,7 @@ def search():
print('result >>>>> {}'.format(result))
return result
except Exception as e:
print('result >>>>> {}'.format(result))
print('Exception >>>>> {}'.format(result))
return result
except Exception as e:
logger.warning(e) #异常返回00

View File

@ -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.Ocrtxt = '../module/ieemoo-ai-assist/document'#post ocr txts
_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
View 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

View File

@ -2,22 +2,15 @@ from obs import ObsClient
from datetime import datetime
#from config import cfg
from utils.config import cfg
import os,threading
import os, sys
import time as ti
import base64,requests,cv2,shutil
lock = threading.Lock()
obsClient = ObsClient(
access_key_id='LHXJC7GIC2NNUUHHTNVI',
secret_access_key='sVWvEItrFKWPp5DxeMvX8jLFU69iXPpzkjuMX3iM',
server='https://obs.cn-east-3.myhuaweicloud.com'
)
bucketName = 'ieemoo-ai'
from utils.up_load_file import up_load
up_load_data = up_load()
def AddObs(file_path, status):
#with lock:
if not cfg.flag:
addobs(file_path, status)
#os.remove(file_path)
else:
if status == '02':
addobs(file_path, status)
@ -42,19 +35,13 @@ def addobs(file_path, status): #save videos
else:
break
if not 'data' in status:
# os.remove(file_path)
return 'can not get the status'
status = status['data']
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]
if objectkey.split('.')[-1] in ['avi','mp4']:
objectkey = 'videos/'+time+'/'+status+'/'+status+'_'+objectkey
if status == '02' or status_:
resp = obsClient.putFile(bucketName, objectkey, file_path)
# shutil.move(file_path, backups_path)
#os.remove(file_path)
if status == '02' or get_weightStatus(objectkey):
up_load_data.upLoad(objectkey, file_path)
def Addimg(uuid_barcode):
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'])
if not os.path.exists(file_path):
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):
file_path = "context.jpg"
cv2.imwrite(file_path, context)
success, encoded_image = cv2.imencode(".jpg",context)
context = encoded_image.tobytes()
time = uuid_barcode.split('-')[0]
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):
uuid = uuid.split('_')[1]
resp = requests.post(url = cfg.riskControl)
up_uuid = resp.json()['data']
#print('>>>>>>>>>>>>>',up_uuid)
if uuid in up_uuid:
return True
return False