如何在MS Azure中为我的Blob存储中的Blob提取上次修改日期 [英] How can I extract Last Modified Date in MS Azure for a blob in my blob storage

查看:111
本文介绍了如何在MS Azure中为我的Blob存储中的Blob提取上次修改日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对MS Azure的世界很陌生. 我正在尝试使用Python获取保存在我的Blob存储中的一堆文件(块Blob)的文件名和最后修改日期.这是我正在使用的代码:

I am pretty new to the world of MS Azure. I am trying to get the filenames and the last modified date for a bunch of files (block blobs) kept in my blob storage using Python. Here is the code that I am using:

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中访问实际的最后修改日期和时间?

The problem here is, that the code tries to create a copy of my files and hence the last modified date is updated to the current date and time. How can I access the actual last modified date and time in Azure ML Studio?

我读到有关Blob.Properties.LastModified的信息,但它似乎在python中不起作用.这里令人困惑的事情之一是关于在CloudBlobs中转换Blob.我不确定是否必须在Python脚本中完成此操作,因为Storage Explorer中的Blob为三种类型:Block,Page和Append.我在这里想念什么吗?

I read about Blob.Properties.LastModified but it doesn't seem to work in python. One of the confusing things here was about converting the blobs in CloudBlobs. I am not sure if this has to be done within the Python script because the blobs in the Storage Explorer are of three types: Block, Page and Append. Am I missing something here?

推荐答案

听起来好像您想在Azure ML Studio中使用Python获取Azure上Blob的last_modified属性.请尝试使用下面的代码.

It sounds like that you want to get the last_modified property of a blob on Azure using Python in Azure ML Studio. Please try to use the code below.

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

如果您不确定某个属性是否存在(例如,如下所示),则可以尝试在Python交互式env中编写<object>.__dict__的代码,以显示Python对象的属性.

And you can try to code <object>.__dict__ in Python interactive env to show the properties of a Python object if you are not sure what property whether or not exists, for example as below.

# 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>}

这篇关于如何在MS Azure中为我的Blob存储中的Blob提取上次修改日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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