当前位置: 首页>>代码示例>>Python>>正文


Python blob.BlobService类代码示例

本文整理汇总了Python中azure.storage.blob.BlobService的典型用法代码示例。如果您正苦于以下问题:Python BlobService类的具体用法?Python BlobService怎么用?Python BlobService使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了BlobService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_tags

def get_tags():
	#TODO: Error checking
#       global d 
#       d = {}

	clarifai_api = ClarifaiApi()
	blob_service = BlobService('calhacks', 'mm7EmY+T+MGahePBDSDU5LHpZR5tRXuh4MSco4jFrzHovOPEf06e18c89pxtPIo4NDVhhjSeaQY/FQmKNxjjyA==')      

	blob_name = request.form['blob_id']
#       blob_name = blob_name.decode('utf-8')
	blob_service.get_blob_to_path('imagestore', blob_name, 'out.png')       
	print("checkpoint 1")
	i = open ('out.png', 'r')
	strd = ""
	for line in i:
		strd += line.strip()
	fname = 'img.png'
	with open (fname, 'wb') as f:
		f.write (base64.b64decode(strd))
		f.close()

	f = open (fname, 'rb')
	result = clarifai_api.tag_images(f)
	st = result['results'][0]['result']['tag']['classes'][0:6]
	print(st)

	for i in []:#['food', 'nobody', 'still life', 'meal', 'dish', 'plate', 'delicious', 'isolated', 'cutout', 'unhealthy', 'one', 'background']: 
		while i in st:
			st.remove(i)
	js = json.dumps(search_terms(st))
	print(js)
	return js
开发者ID:Hersh500,项目名称:pie-piper,代码行数:32,代码来源:server_without_timeout.py

示例2: _createExternalStore

 def _createExternalStore():
     from toil.jobStores.azureJobStore import _fetchAzureAccountKey
     blobService = BlobService(account_key=_fetchAzureAccountKey(AzureJobStoreTest.accountName),
                               account_name=AzureJobStoreTest.accountName)
     containerName = 'import-export-test-%s' % uuid.uuid4()
     blobService.create_container(containerName)
     return containerName
开发者ID:guillermo-carrasco,项目名称:toil,代码行数:7,代码来源:jobStoreTest.py

示例3: submit

def submit():
    blob_service = BlobService(account_name=ACCOUNT_NAME, account_key=ACCOUNT_KEY)

    # Get a SAS signature (read for 24 hours) for the input container save to a string
    inputsig = sasUrl(account=ACCOUNT_NAME, key=ACCOUNT_KEY, container=INPUT_CONTAINER, permission='r')

    # Get a SAS signature (write for 24 hours) for the output container save to a string
    outputsig = sasUrl(account = ACCOUNT_NAME, key = ACCOUNT_KEY, container = OUTPUT_CONTAINER, permission = 'rwl')

    # List all the blobs and dump the content to a string
    blobs = blob_service.list_blobs(INPUT_CONTAINER)

    bloblist = []
    for blob in blobs:
        bloblist.append(blob.name)

    os.environ[SLURMDEMO_INPUTSIG] = inputsig
    os.environ[SLURMDEMO_OUTPUTSIG] = outputsig
    os.environ[SLURMDEMO_BLOBLIST] = json.dumps(bloblist)
    os.environ[SLURMDEMO_INPUTCONTAINER] = INPUT_CONTAINER
    os.environ[SLURMDEMO_OUTPUTCONTAINER] = OUTPUT_CONTAINER
    os.environ[SLURMDEMO_INPUTACCOUNT] = ACCOUNT_NAME
    os.environ[SLURMDEMO_OUTPUTACCOUNT] = ACCOUNT_NAME

    # Call sbatch
    cli = "sbatch -N 2 -n 2 --array=0-{nb} slurmdemo.sh".format(nb=len(bloblist))
    run(cli, showoutput=True)
开发者ID:Angp4s,项目名称:computerscience,代码行数:27,代码来源:slurmdemo.py

示例4: getblob

def getblob(request):
    assert isinstance(request, HttpRequest)
    blob_service = BlobService(account_name='araldrift', account_key='YOURKEYGOESHERE')
    # http://<storage-account-name>.blob.core.windows.net/<container-name>/<blob-name>
    blob_service.get_blob_to_path('flow', 'NARYN.day', './NARYN.day')  
    # return HttpResponse('ok ye of little faith')
    return HttpResponse(json.dumps('i am just a wee bit of json'))
开发者ID:robfatland,项目名称:djurassic,代码行数:7,代码来源:api.py

示例5: __create_blob_container

	def __create_blob_container(self, storage_acc_name):
		sms = self.__get_service_mgmt_object()

		# Retrieve the primary key of your storage account
		# Maybe the secondary key works too?
		storage_acc_key = None
		acounts = sms.list_storage_accounts()
		for account in acounts:
		    if account.service_name == storage_acc_name:
		        storageServiceObj = sms.get_storage_account_keys(account.service_name)
		        storage_acc_key = storageServiceObj.storage_service_keys.primary


		# Create a container
		blob_service = BlobService(account_name=storage_acc_name,
		                           account_key=storage_acc_key)

		container_name = namesgenerator.get_random_name()
		container_name += "container"
		blob_service.create_container(container_name)

		# This is the url to the container we just created
		container_url_template = "http://{}.blob.core.windows.net/{}"
		container_url = container_url_template.format(storage_acc_name, container_name)
		#print "Created blob container with URL ",container_url
		return container_url
开发者ID:srm912,项目名称:ansible-provisioning,代码行数:26,代码来源:azure_provider.py

示例6: enumerate_objects

def enumerate_objects(container):
    blob_service = BlobService(AZURE_ACCOUNT_NAME, AZURE_ACCOUNT_KEY)
    blobs = blob_service.list_blobs(container)
    items = []
    for blob in blobs:
        items.append(blob.name)

    return items
开发者ID:fergalmoran,项目名称:dss.api,代码行数:8,代码来源:cdn.py

示例7: gethydrograph

def gethydrograph(request):
    '''
    JSON return of a particular hydorgaph by start / stop / station / time interval

    In response it will 
        generate a 404 error if the value is not found
        or
        return a JSON response with the requested slice.
    '''
    assert isinstance(request, HttpRequest)
    
    start  = request.GET.get('start', None)
    end = request.GET.get('end', None)

    # Here we can thieve the time parse code from LOS and use this line: 
    # rd, rh = extract_time(request)
    # but for now this is commented out of course

    station = request.GET.get('station',None)
    interval  = request.GET.get('interval',None)

    blob_service = BlobService(account_name='araldrift', account_key='XXXXXXXXXXXXXXXXXXXXXXX')
    blob_service.get_blob_to_path('flow', 'NARYN.day', './tmp.csv')  
    f = file('./tmp.csv')
    h = []
    while True:
        line = f.readline()
        if line == "": break
        h.append(line)
    f.close()
    json_encoded_result = json.dumps(h)

    # Keep the LOS original for reference (see time formatting): 
    # clean_req = {"rdidx": rdidx,"rdepth": rdepth,"rd": rd.strftime("%Y%m%d"), "rh": rh,"rparm": rparm,}
    # clean_req = {"start": start, "end": end, "station": station, "interocitor": interval,}
    # json_request = json.dumps(clean_req)
    # json_encoded_result = json_request

    try:
        #####################
        #
        # This is the commented out LOS code (stripped out)
        #
        #####################
        # Convert the depth to an int.
        # depthIndex = int(rdidx)
        # Get the depth slice from the dataset.
        # ret = getDepthSliceByIndex((rd,rh), depthIndex, rparm, rnorm)
        # Serialize out to JSON.
        # json_encoded_result = json.dumps(ret)
        # Cache the response to blob storage. (Would be great if this was async...)
        # cacheResult(request.GET, json_encoded_result)
        # Send the view on to the client.
        #####################

        return HttpResponse(json_encoded_result, content_type="application/json" )
    except Exception as a:
        return HttpResponseNotFound(content="No dice, either the inputs were out of range, the file couldn't be retrieved, or the winds weren't in your favor.")
开发者ID:robfatland,项目名称:djak,代码行数:58,代码来源:api.py

示例8: gethydrograph

def gethydrograph(request):
    '''
    Returns streamflow data by start / stop / station 
    In response it will 
        generate a 404 error if the value is not found
        or
        return a JSON response with the requested slice or a .csv file by default
    '''
    assert isinstance(request, HttpRequest)
    
    start  = request.GET.get('start', None)
    end = request.GET.get('end', None)
    station = request.GET.get('station',None)
    interval  = request.GET.get('interval',None)
    jsondat = request.GET.get('jsondat',None)
    plot = request.GET.get('plot',None)

    #start blob service
    stationfile = station + '.day.new'
    downloadablefile = station + '_' + start + '_' + end + '.csv'
    blob_service = BlobService(account_name='araldrift', account_key='otLzzkwQHQD3xFTQxwxy64PCL6eDINWGjSB7x6Ta2XVw3+3ffI5O2MhAEavf/r8qIW4G/dKrZAVg1R64nK7hDQ==')
    blob_service.get_blob_to_path('flow', stationfile, './tmp.csv')  
    f = file('./tmp.csv')
    
    #read in pandas data and subsetting
    d_cols = ["DATE","FLOW"]
    d = pd.read_csv('./tmp.csv', sep=" ", names=d_cols)
    df = d[(d.DATE >= start) & (d.DATE <= end)] 
    h = df.to_json(orient='records')
    json_encoded_result = json.dumps(h)
    df.plot(x='DATE', y='FLOW', figsize=(14,6))
    plt.savefig('./plot_test.png')
   
   
    #h = []
    #while True:
     #   line = f.readline()
      #  if line == "": break
       # h.append(line)
    #f.close()
    try:
        if jsondat in ['TRUE']:
           response = HttpResponse(json_encoded_result, content_type="application/json" )
           return response

        elif plot in ['TRUE']:
            image_data = open("./plot_test.png", "rb").read()
            response = HttpResponse(image_data, content_type='image/png')
            return response

        else:
            response = HttpResponse(content_type='text/csv')
            response['Content-Disposition'] = 'attachment; filename=' +downloadablefile
            df.to_csv(response, index=False, lineterminator='\r\n')
            return response
    except Exception as a:
        return HttpResponseNotFound(content="No dice, either the inputs were out of range, the file couldn't be retrieved, or the winds weren't in your favor.")
开发者ID:amandalehr,项目名称:araldif,代码行数:57,代码来源:api.py

示例9: upload_from_text

def upload_from_text(container, content):
    filename = str(uuid.uuid4())

    blob_service = BlobService(account_name=config.AZURE_STORAGE_NAME, account_key=config.AZURE_STORAGE_KEY)
    try:
        blob_service.put_block_blob_from_text(container, filename, content)
        return generate_blob_url(container, filename)
    except:
        return ""
开发者ID:hungys,项目名称:DockerVC,代码行数:9,代码来源:azure_storage.py

示例10: _createExternalStore

    def _createExternalStore(self):
        from toil.jobStores.azureJobStore import _fetchAzureAccountKey
        from azure.storage.blob import BlobService

        blobService = BlobService(account_key=_fetchAzureAccountKey(self.accountName),
                                  account_name=self.accountName)
        containerName = 'import-export-test-%s' % uuid.uuid4()
        blobService.create_container(containerName)
        return containerName
开发者ID:python-toolbox,项目名称:fork_toil,代码行数:9,代码来源:jobStoreTest.py

示例11: AzureStorage

class AzureStorage(Storage):
    account_name = settings.AZURE_ACCOUNT_NAME
    account_key = settings.AZURE_ACCOUNT_KEY
    azure_container = settings.AZURE_CONTAINER

    def __init__(self, *args, **kwargs):
        super(AzureStorage, self).__init__(*args, **kwargs)
        self._connection = None

    @property
    def connection(self):
        if self._connection is None:
            # Create connection
            self._connection = BlobService(self.account_name, self.account_key)
            
            # Create container if needed
            containers = [c for c in self._connection.list_containers(prefix=self.azure_container) if c.name == self.azure_container ]
            if len(containers) == 0:
                self._connection.create_container(self.azure_container, {'origin': 'created by Django web app'}, fail_on_exist=True)

        return self._connection

    def _open(self, name, mode="rb"):
        stream = SimpleUploadedFile(name, None)
        self.connection.get_blob_to_file(self.azure_container, name, stream)
        stream.seek(0)
        return stream

    def exists(self, name):
        try:
            self.connection.get_blob_properties(self.azure_container, name)
        except AzureMissingResourceHttpError:
            return False
        else:
            return True

    def delete(self, name):
        self.connection.delete_blob(self.azure_container, name)

    def size(self, name):
        properties = self.connection.get_blob_properties(self.azure_container, name)
        return properties["content-length"]

    def _save(self, name, content):
        self.connection.put_block_blob_from_file(self.azure_container, name, content)
        return name

    def url(self, name):
        ap = AccessPolicy(expiry=(timezone.datetime.utcnow() + timezone.timedelta(seconds=600)).strftime('%Y-%m-%dT%H:%M:%SZ'), \
                          start=(timezone.datetime.utcnow() + timezone.timedelta(seconds=-600)).strftime('%Y-%m-%dT%H:%M:%SZ'), \
                          permission='r')
        sap = SharedAccessPolicy(ap)
        sas = SharedAccessSignature(self.account_name, self.account_key)
        url = sas.generate_signed_query_string(path=self.azure_container + '/' + name, resource_type='b', shared_access_policy=sap)
        
        return self.connection.make_blob_url(self.azure_container, name) + "?" + url
开发者ID:marcanpilami,项目名称:MAGE,代码行数:56,代码来源:storage.py

示例12: uploadFile

def uploadFile(sourceFile, destUrl, destKey):
    storageparts = split_storage_url(destUrl)
    blobservice = BlobService(storageparts[0], destKey)
    try:
        fh=open(sourceFile, "r")
    except:
        print "No such file", sourceFile
        return
    log('uploading ' + str(sourceFile), True)
    blobservice.put_page_blob_from_file(storageparts[2], sourceFile, fh, getsize(sourceFile))
开发者ID:MSSedusch,项目名称:azcopy-py,代码行数:10,代码来源:azcopy.py

示例13: generateImageUrl

def generateImageUrl(request):
    account_name = "faceemoji"
    account_key = "kaoJiy0T7r6sXyo4wFYKCLgpAXbILKvkloeF+kFpCEUxC+bL9BxGA3WtofVxHcLPn3lMjw/UO/0sS1GCN3/AQw=="
    blob_service = BlobService(account_name, account_key)
    content = base64.b64decode(request.data)
    st = datetime.datetime.fromtimestamp(time.time()).strftime('%Y-%m-%d-%H-%M-%S')
    blob_name = hashlib.sha224(st).hexdigest() + 'image.png'
    blob_service.put_block_blob_from_bytes('image', blob_name, content)
    img_url = blob_service.make_blob_url('image', blob_name)
    return img_url
开发者ID:hongdp,项目名称:FaceEmoji,代码行数:10,代码来源:app.py

示例14: upload_file_to_azure

def upload_file_to_azure(in_file, file_name, container_name=settings.AZURE_CONTAINER):
    try:
        blob_service = BlobService(AZURE_ACCOUNT_NAME, AZURE_ACCOUNT_KEY)
        blob_service.put_block_blob_from_path(
            container_name=container_name,
            blob_name=file_name,
            file_path=in_file,
            x_ms_blob_content_type='application/octet-stream'
        )
    except Exception as ex:
        print("Failed to upload blob: {0}".format(ex))
开发者ID:fergalmoran,项目名称:dss.api,代码行数:11,代码来源:cdn.py

示例15: getblob

def getblob(request):
    assert isinstance(request, HttpRequest)
    blob_service = BlobService(account_name='araldrift', account_key='otLzzkwQHQD3xFTQxwxy64PCL6eDINWGjSB7x6Ta2XVw3+3ffI5O2MhAEavf/r8qIW4G/dKrZAVg1R64nK7hDQ==')
    # http://<storage-account-name>.blob.core.windows.net/<container-name>/<blob-name>
    name = 'test.txt'
    fpath = '{0}\{1}'.format(tempfile.gettempdir(),name)
    blob_service.get_blob_to_path('flow', 'NARYN.day', fpath)
    response = HttpResponse(content_type='text/plain')
    response['Content-Disposition'] = 'attachment; filename=test.txt'
    blob.Properties.ContentDisposition = "attachment; filename=" + downloadName;
    return response
开发者ID:amandalehr,项目名称:araldif,代码行数:11,代码来源:api.py


注:本文中的azure.storage.blob.BlobService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。