from obs import ObsClient from datetime import datetime #from config import cfg from utils.config import cfg import os,threading 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' 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) else: objectkey = os.path.basename(file_path) f_dist = os.sep.join([cfg.tempvideos, status+'_'+objectkey]) shutil.move(file_path, f_dst) def addobs(file_path, status): #save videos ti.sleep(1) videoUuid = os.path.basename(file_path).split('_')[1] json_data = {'videoUuid': videoUuid} for vre in [cfg.VreTest, cfg.VreTest2, cfg.Vre]: resp = requests.post(url=vre, data=json_data) status = resp.json() if not 'data' in status:#延迟设置 ti.sleep(1) resp = requests.post(url=vre, data=json_data) status = resp.json() if 'data' in status: break 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) def Addimg(uuid_barcode): time = uuid_barcode.split('-')[0].split('_')[-1] objectkey = 'imgs/'+time+'/'+uuid_barcode+'.jpg' file_path = os.sep.join([cfg.Tempimg, '5_'+uuid_barcode+'.jpg']) if not os.path.exists(file_path): 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) def Addimg_content(uuid_barcode, 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) 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 if __name__ == '__main__': import cv2 context = cv2.imread('/home/lc/project/ieemoo-ai-search/data/imgs/20230625-094651_37dd99b0-520d-457b-8615-efdb7f53b5b4_6907992825762.jpg') uuid_barcode = '20230625-094651_37dd99b0-520d-457b-8615-efdb7f53b5b4' Addimg_content(uuid_barcode, context)