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
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)
Secondly, how can I then download this file? I found the key.getfile() command but I cant work how to implement it.
Based on your format
latest = max(keys)should get the latest itemTo download the content of of the file your can use
or
See more details in boto documentations for S3