def query_cld_folder(folder): files = {} next_cursor = True expression = Search().expression(f"folder:{folder}/*").with_field( "image_analysis").max_results(500) while next_cursor: res = expression.execute() for asset in res['resources']: rel_path = path.relpath(asset['public_id'], folder) files[rel_path] = { "type": asset['type'], "resource_type": asset['resource_type'], "public_id": asset['public_id'], "format": asset['format'], "etag": asset.get('etag', '0'), "relative_path": rel_path, # save for inner use } # use := when switch to python 3.8 next_cursor = res.get('next_cursor') expression.next_cursor(next_cursor) return files
from cloudinary import Search import urllib.request cloudName = 'dth0ow8ry' api_key = 293352914274159 api_secret = 'wLi2XaqNePSx2f9jAFDX39vqTzg' target_directory = '/Users/Richard/Documents/UCI/HackUCI2020/unknown/' search = Search() search.expression('face') faces = search.execute(cloud_name=cloudName, api_key=api_key, api_secret=api_secret) for i, item in enumerate(faces['resources']): urllib.request.urlretrieve(item['url'], f"{target_directory}{item['filename']}{i}.{item['format']}") print('Faces downloaded')