datetime - process the files in S3 based on their timestamp using python and boto -


i trying process files in s3 based on timestamp these files have. have code provides me date modified attribute of files , parse convert appropriate format using boto.utils.parse_ts. want sort files , if possible put key name in list in sorted order oldest files comes first processing. how can this?

con = s3connection('', '') bucket = conn.get_bucket('bucket') keys = bucket.list('folder1/folder2/')  key in keys:     date_modified = parse_ts(key.last_modified) 

there lots of ways here's 1 way should work:

import boto.s3 conn = boto.s3.connect_to_region('us-east-1') bucket = conn.get_bucket('mybucket') keys = list(bucket.list(prefix='folder1/folder2/')) keys.sort(key=lambda k: k.last_modified) 

the variable keys should list of key objects sorted last_modified attribute oldest first , newest last.


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -