Skip to content

Instantly share code, notes, and snippets.

@cbare
Created June 28, 2016 20:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cbare/1fcbe682add652ef15c75d69d6b0dc7b to your computer and use it in GitHub Desktop.
Save cbare/1fcbe682add652ef15c75d69d6b0dc7b to your computer and use it in GitHub Desktop.
Download pilot images for the DM Challenge from an S3 bucket
import os
from boto.s3.connection import S3Connection
from boto.s3.connection import OrdinaryCallingFormat
## retrieve AWS credentials from environment variables
aws_key = os.getenv('AWS_KEY_ID')
aws_secret = os.getenv('AWS_SECRET_KEY')
## Ordinary calling format necessary because of dots in
## bucket name. See: https://github.com/boto/boto/issues/2836
conn = S3Connection(aws_key, aws_secret, calling_format=OrdinaryCallingFormat())
bucket = conn.get_bucket('dmchallenge.synapse.org')
prefix = 'grouphealth//'
i = 0
with open('images_crosswalk_pilot.tsv') as f:
headers = f.readline().split('\t')
col = headers.index('filename')
for line in f:
filename = line.strip().split('\t')[col]
i += 1
print(i, filename)
key = bucket.get_key(prefix+filename)
key.get_contents_to_filename(filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment