def query(persistentId): #print(persistentId) auth = qiniu.Auth(accessKey, secretKey) url = 'http://{0}/status/get/prefop?id={1}'.format(config.API_HOST, persistentId) retData, respInfo = http._get(url, params=None, auth=auth) if retData != None: print("Success: (" + persistentId + ")") print("---id:" + retData["id"]) print("---code:" + str(retData["code"])) print("---desc:" + retData["desc"]) for item in retData["items"]: print("---cmd:" + item["cmd"]) print("------code:" + str(item["code"])) print("------desc:" + item["desc"]) if item.__contains__("error"): print("------error:" + item["error"]) if item.__contains__("hash"): print("------hash:" + item["hash"]) if item.__contains__("key"): print("------key:" + item["key"]) else: #print(respInfo) print("Error (" + persistentId + "):") print("--StatusCode:" + str(respInfo.status_code)) print("--Reqid:" + respInfo.req_id) print("--Message:" + respInfo.error) print("\r\n")
def domain_list(): params = {'marker': '', 'limit': 100} json_data, response_info = http._get('http://api.qiniu.com/domain', params, at) if response_info.status_code != 200: raise Exception("get domain list error") for d in json_data['domains']: yield d['name']
def get_prop_status(self, persistent_id: str): """ 查询持久化处理状态 https://developer.qiniu.com/dora/api/1294/persistent-processing-status-query-prefop :param persistent_id: :return: """ url = self.BASE_URL + '/status/get/prefop?id=' + persistent_id ret, info = http._get(url=url, params=None, auth=None) return ret, info
def nrop(args): """ adult image recognition, save results to key\tjson string """ assert (args.bucket_name != None) assert (args.remote_dir != None) assert (args.input_file != None) assert (args.output_file != None) bucket_name = args.bucket_name # with open(args.input_file) as fh: # paths = filter(None, fh.readlines()) img_num = 0 for video in os.listdir(args.input_file): with open(os.path.join(args.input_file, video)) as fh: paths = filter(None, fh.readlines()) print paths results = {} if os.path.exists(os.path.join(args.output_file, video)): with open(os.path.join(args.output_file, video), 'r') as fh: while True: line = fh.readline().strip() if len(line) == 0: break path, res = line.split('\t') results[path] = res with open(os.path.join(args.output_file, video), 'a') as fh: try: for path in paths: # path = path.split()[0] if path not in results: url = '%s/%s%s%s?nrop' % (remote_url, args.remote_dir, '%5C', (path.replace('\\', '%5C')).strip()) print url res = http._get(url, None, q)[0] logging.info('results of %s' % path) logging.info(str(res)) assert res['code'] == 0 results[path] = str(res) fh.write('%s\t%s\n' % (path, results[path])) else: print path, ' already processed' except Exception as e: print 'error occured: ', e.message img_num += 1 print '%d images recognized' % (img_num)
def vframe_interval(videoLink, picCount, picFormat, width, height, fromBucket, fromKey, saveBucket=None, savePicPrefix=None, usePipeline="", notifyUrl=None): auth = qiniu.Auth(accessKey, secretKey) url = '{0}?avinfo'.format(videoLink) retData, respInfo = http._get(url, params=None, auth=auth) if retData != None: videoData = retData["format"] duration = int(float(videoData["duration"])) offset_slice = duration / picCount for i in range(picCount): vframe.vframe(picFormat, offset_slice * i, width, height, "auto", fromBucket, fromKey, saveBucket=saveBucket, saveKey=savePicPrefix + str(i + 1) + "." + picFormat, usePipeline=usePipeline, notifyUrl=notifyUrl) else: print("Error:" + respInfo["error"])
def __get(self, url, params=None): return http._get(url, params, self.auth)
def __get(self, url, params=None): return http._get(self.server + "/" + url, params, self.auth)
def domain_info(domain): json_data, response_info = http._get( 'http://api.qiniu.com/domain/%s' % domain, None, at) if response_info.status_code != 200: raise Exception("get domain info error") return json_data
def __get(self, url, params=None): headers = {'Content-Type': 'application/json'} return http._get(url, params, self.auth)
def __get(self, url, params=None): if params is None: return http._get_with_qiniu_mac(url, params, self.auth) else: return http._get(url, params, self.auth)