S3宝途下载 - 最新 [英] S3 Boto Downloading - Most Recent
问题描述
我是新来的Python编码和还没有能够就这一进展。我有一段时间了连接按以下格式codeD文件名:
I am new to Python coding and havent been able to progress on this. I have some time encoded filenames in the following format:
20121208151318.gzip
20121208151320.gzip
20121208151322.gzip
20121208151325.gzip
20121208151326.gzip
使用这个code,我可以打印所有文件的文件名在我的S3存储桶:
Using this code I can print the filenames of all the files in my S3 bucket:
import boto
s3conn = boto.connect_s3()
bucket = s3conn.lookup('my_bucket_name')
for key in bucket:
print k.name
key.getfile()
我需要两方面的帮助。首先,我怎么能得到最新的文件在斗,这在我的情况是名称:
I need help with two aspects. Firstly how can I get the name of the most recent file in the bucket, which would in my case be:
20121208151326 (15:13:26 - 8th December 2012)
其次,我怎么能那么下载此文件?我发现key.getfile()命令,但我不能工作,如何实现它。
Secondly, how can I then download this file? I found the key.getfile() command but I cant work how to implement it.
推荐答案
根据您的格式最新= MAX(键)
应该得到最新的项目
Based on your format latest = max(keys)
should get the latest item
要下载您可以使用该文件的内容
To download the content of of the file your can use
latest.get_contents_to_filename(<file_name>)
或
latest.get_contents_to_file(<file>)
见博托单证为S3 详情
这篇关于S3宝途下载 - 最新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!