Skip to content

Instantly share code, notes, and snippets.

@robballou
Created August 23, 2012 21:29
Show Gist options
  • Save robballou/3442080 to your computer and use it in GitHub Desktop.
Save robballou/3442080 to your computer and use it in GitHub Desktop.
Work on transering file(s) to Glacier
#!/usr/bin/env python
import argparse
import tempfile
import os
from boto.s3.connection import S3Connection
parser = argparse.ArgumentParser(description='description')
parser.add_argument('bucket')
args = parser.parse_args()
print "[ ] Connecting to S3"
conn = S3Connection()
buckets = conn.get_all_buckets()
print "[ ] Connected"
found_bucket = False
for bucket in buckets:
if bucket.name == args.bucket:
found_bucket = True
break
if not found_bucket:
raise Exception("Could not find bucket: %s" % args.bucket)
print "[ ] Found bucket"
keys = bucket.get_all_keys()
print "[ ] Number of objects in bucket: %d" % len(keys)
for key in keys:
if key.name.endswith('.mp3') or key.name.endswith('m4p'):
print "[ ] Downloading %s" % key.name
tfile = tempfile.mkstemp()
# print tfile
key.get_contents_to_filename(tfile[1])
os.unlink(tfile[1])
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment