# Python Boto Script - Sorting based on date

I had a question regarding my code which downloads a file from S3 with the highest (most recent) timedated filename format:

YYYYMMDDHHMMSS.zip

from boto.s3.connection import S3Connection
from boto.s3.key import Key
import sys
conn = S3Connection('____________________', '________________________________________')
bucket = conn.get_bucket('bucketname')
rs = bucket.list("FamilyPhotos")

for key in rs:
print key.name

keys = [(key,datetime.strptime(key.name,'%Y%m%d%H%M%S.zip')) for key in rs]
sorted(keys, key = lambda element : element[1])
latest = keys[0][1]
latest.get_contents_to_filename()


I havent done a lot of python before so I would really appreciate some feedback.

-
What are you looking for specifically? –  Michel Ayres Dec 18 '12 at 12:16
The part of the script that works out the most recently dated filename. I am sure there is a better way of doing it. –  Jimmy Dec 18 '12 at 12:34

The names will properly compare lexically even without converting them to datetimes, and you can just use the max function:
from boto.s3.connection import S3Connection