从存储桶Google Cloud加载数据 [英] Load data from bucket google cloud

查看:76
本文介绍了从存储桶Google Cloud加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是从Google云存储桶加载数据的功能.

Here is a function to load data from google cloud bucket.

action_dataset_folder_path = 'action-data-set'
zip_path = 'actions.zip'
url='http://console.cloud.google.com/storage/browser/actions'

class LoadProgress(tqdm):
    last_block = 0

    def hook(self, block_num=1, block_size=1, total_size=None):
        self.total = total_size
        self.update((block_num - self.last_block) * block_size)
        self.last_block = block_num

if not isfile(zip_path):
    with LoadProgress(unit='B', unit_scale=True, miniters=1, desc='actions-Dataset') as pbar:
        urlretrieve(
            url,
            zip_path,
            pbar.hook)
if not isdir(action_dataset_folder_path):
    with tarfile.open(zip_path) as tar:
        tar.extractall()
        tar.close()
print('All done ...!')

该文件下载为空文件,大小为73.7KB!我不明白!看来一切都很好.

The file is downloaded as empty file with 73.7KB! I did not understand! It seems everything is good.

推荐答案

以下是来自Google云网站的代码:

Here is the code from google cloud site:python-code

    from gcloud import storage
    def download_blob(bucket_name, source_blob_name, destination_file_name):
        """Downloads a blob from the bucket."""
        storage_client = storage.Client()
        bucket = storage_client.get_bucket(bucket_name)
        blob = bucket.blob(source_blob_name)

        blob.download_to_filename(destination_file_name)

        print('Blob {} downloaded to {}.'.format(
            source_blob_name,
            destination_file_name))
download_blob("datset","actions", "dataset")

这篇关于从存储桶Google Cloud加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆