def unzip(path):
    zipfilename = os.path.split(path)[1]
    zipparts = zipfilename.split('.')
    try:
        zfile = zipfile.ZipFile(path)
        for name in zfile.namelist():
            filename = os.path.split(name)[1]
            parts = filename.split('.')
            s3_key = zipparts[0]+'.'+parts[0]+'.csv'
            # store data to S3 bucket
            to_pending(s3_key, zfile.read(name))
        zfile.close()
    except zipfile.BadZipfile:
        print "\nBadZipfile %s" % zipfilename
    finally:
        os.remove(path)
#!/usr/bin/env python

import sys
from redshift import done_bucket,from_done,to_pending

for key in done_bucket.list():
    print key.name
    content = from_done(key)
    # copy CSV to done
    to_pending(key, content)
    # remove CSV from pending
    done_bucket.delete_key(key)