微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何在MS Azure中为blob存储中的blob提取上次修改日期

我是MS Azure世界的新手.
我试图获取使用Python保存在我的blob存储中的一堆文件(块blob)的文件名和最后修改日期.这是我正在使用的代码

import datetime
from azure.storage.blob import BlockBlobService
blob_service = BlockBlobService(account_name=account, account_key=acckey,protocol='http', request_session=sess)
blob_service.get_blob_to_path(container, pdfname, pdflocal)
generator = blob_service.list_blobs(container)
filenames = []
for blob in generator:
    print (blob.name)
    pdflocal = './' + blob.name
    properties=blob_service.get_blob_to_path(container, blob.name,pdflocal)
    date_year = datetime.datetime.fromtimestamp(os.path.getmtime("./"+blob.name) ).strftime('%Y-%m-%d %H:%M:%s')
    print (date_year)
    filenames.append(blob.name)
print len(filenames)

这里的问题是,代码试图创建我的文件的副本,因此最后修改日期更新为当前日期和时间.如何在Azure ML Studio中访问实际的上次修改日期和时间?

我读到了Blob.Properties.LastModified,但它似乎不适用于python.这里令人困惑的事情之一是关于在CloudBlobs中转换blob.我不确定是否必须在Python脚本中完成,因为存储资源管理器中的blob有三种类型:Block,Page和Append.我在这里错过了什么吗?

解决方法:

听起来你想在Azure ML Studio中使用Python获取Azure上的blob的last_modified属性.请尝试使用以下代码.

for blob in generator:
    last_modified = blob.properties.last_modified
    print(last_modified)

您可以尝试在Python交互式环境中编写< object> .__ dict__来显示Python对象的属性,如果您不确定是否存在哪个属性,例如如下所示.

# Show the properties of a Blob object
>>> blob.__dict__
{'content': '', 'Metadata': {}, 'snapshot': None, 'name': 'test.tmp',
 'properties': <azure.storage.blob.models.BlobProperties object at 0x7f4f8f870110>}
# Show the properties of the BlobProperties Object
>>> blob.properties.__dict__
{'content_length': 99831, 'blob_type': 'BlockBlob', 'append_blob_committed_block_count': None, 
 'last_modified': datetime.datetime(2016, 11, 23, 5, 46, 10, tzinfo=tzutc()), 'content_range': None, 'etag': '"0x8D4136407173436"', 'page_blob_sequence_number': None, 'content_settings': <azure.storage.blob.models.ContentSettings object at 0x7f4f8f870510>, 'copy': <azure.storage.blob.models.copyProperties object at 0x7f4f8f870650>, 'lease': <azure.storage.blob.models.LeaseProperties object at 0x7f4f8f870810>}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐