import boto
#http://www.laurentluce.com/posts/upload-and-download-files-tofrom-amazon-s3-using-pythondjango/
#http://boto.cloudhackers.com/en/latest/s3_tut.html
#http://www.programcreek.com/python/example/53063/boto.s3.key.set_metadata
#https://techietweak.wordpress.com/2016/05/16/file-handling-in-aws-s3-with-python-boto-library/
# Let's use Amazon S3
#s3 = boto3.resource('s3')

import sys, os
from boto.s3.key import Key

def upload():
    print "Uploading"

def download():
    LOCAL_PATH = '/Users/muthuselvan/Downloads/CI/'
    AWS_ACCESS_KEY_ID = 'AKIAI4G5PI6KVC3W7A6Q'
    AWS_SECRET_ACCESS_KEY = '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'
    bucket_name = 'jaf-jar'
    conn = boto.connect_s3(AWS_ACCESS_KEY_ID,AWS_SECRET_ACCESS_KEY)
    bucket = conn.get_bucket(bucket_name)
    # go through the list of files

    bucket_list = bucket.list()

    for l in bucket_list:

      keyString = str(l.key)
      print "Downloading ..",keyString
 

      # check if file exists locally, if not: download it

      if not os.path.exists(LOCAL_PATH+keyString):
       l.get_contents_to_filename(LOCAL_PATH+keyString)
       
download()       
       
    

