import tinys3, os
from os import listdir

conn = tinys3.Connection(os.environ['AWS_ACCESS_KEY_ID'], os.environ['AWS_SECRET_ACCESS_KEY'], tls=True, endpoint='s3-eu-west-1.amazonaws.com')

for key in listdir('.'):
    extension = key.split('.')[-1]
    content_type = 'text/plain'
    if extension == 'js':
        content_type = 'application/x-javascript'
    elif extension in ['css', 'html']:
        content_type = 'text/' + extension
    print(key, extension, content_type)
    print(conn.update_metadata(key, {'Content-Encoding' : 'gzip', 'Content-Type': content_type}, os.environ['S3_BUCKET']))
