J'ai un serveur S3 avec des millions de fichiers sous chaque compartiment. Je veux télécharger des fichiers à partir d'un compartiment, mais pour télécharger uniquement des fichiers répondant à une condition particulière. Existe-t-il un meilleur moyen que d'obtenir tous les seaux, puis de vérifier la condition particulière lors de l'itération sur les fichiers? Comme on peut le voir ici:Boto3 Amazon S3 (package Python) - obtention uniquement des fichiers qui remplissent une condition (un bucket.list filtré())
import os
# Import the SDK
import boto
from boto.s3.connection import OrdinaryCallingFormat
LOCAL_PATH = 'W:/RD/Fancy/s3_opportunities/'
bucket_name = '/recording'#/sampledResponseLogger'
# connect to the bucket
print 'Connecting...'
conn = boto.connect_s3(calling_format=OrdinaryCallingFormat()) #conn = boto.connect_s3()
print 'Getting bucket...'
bucket = conn.get_bucket(bucket_name)
print 'Going through the list of files...'
bucket_list = bucket.list()
for l in bucket_list:
keyString = str(l.key)
# SOME CONDITION
if('2015-08' in keyString):
# check if file exists locally, if not: download it
filename=LOCAL_PATH+keyString[56:]
if not os.path.exists(filename):
print 'Downloading file: ' + keyString + '...'
# Download the object that the key represents
l.get_contents_to_filename(filename)