import boto3
# Set up MinIO client
ENDPOINT='https://s3-mxqr.almnube.telmex.com'
ACCESS_KEY='55711507b8ebd71a6314'
SECRET_KEY='1NnRhopRTTdcFxw6c5yPxqqLCcNU6vcG2CZV/7NK'
BUCKET_NAME = 'daas-sgm-stg'

s3 = boto3.client('s3',
                  endpoint_url=ENDPOINT,
                  aws_access_key_id=ACCESS_KEY,
                  aws_secret_access_key=SECRET_KEY,
                  verify=False)
# Create a bucket
# cr = s3.create_bucket(Bucket=BUCKET_NAME)
# print(cr)
# Upload a file to the bucket
# s3.upload_file('myfile.txt', 'mybucket', 'myfile.txt')
# List objects in the bucket
response = s3.list_objects(Bucket=BUCKET_NAME)
#for obj in response.get('Contents', []):
#    print(obj['Key'])
# Listar objetos en el bucket

# Inicializar el total
total_size = 0

# Iterar sobre los objetos y mostrar el nombre, tamaño y sumar el total
for obj in response.get('Contents', []):
    file_size = obj['Size']
    total_size += file_size
    print(f"Archivo: {obj['Key']}, Tamaño: {file_size} bytes")

# Mostrar el tamaño total
print(f"\nTamaño total de los archivos: {total_size} bytes ({total_size / (1024 ** 2):.2f} MB)")

