以下是从Google云端桶加载数据的功能。
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的空文件下载!我不明白!似乎一切都很好。
答案 0 :(得分:0)
以下是Google云网站的代码: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")
答案 1 :(得分:-1)
您可以使用GET request从Google云端存储中检索数据。在Python中,您可以使用Requests库执行此操作。
首先,您需要检索身份验证代码(您可以使用OAuth 2.0 Playground)
进行测试然后你可以使用这样的东西来检索数据(对象):
import requests
authCode = YOUR_AUTH_CODE
auth = "Bearer " + authCode
myHeaders = {"Authorization": auth}
r = requests.get('https://www.googleapis.com/storage/v1/b/BUCKET_NAME/o/OBJECT_NAME', headers=myHeaders)
print r.text
print r.status_code