39 lines
1.0 KiB
Python
39 lines
1.0 KiB
Python
"""Script to move minio images to subfolder."""
|
|
|
|
from pathlib import Path
|
|
|
|
from dotenv import load_dotenv
|
|
from PIL import Image
|
|
|
|
from shared.data_store import connect, get, put_image
|
|
from shared.utils import setup_logging
|
|
|
|
if __name__ == '__main__':
|
|
# load in env file
|
|
env_path = Path(__file__).parent.parent / 'server.env'
|
|
assert env_path.exists()
|
|
load_dotenv(env_path)
|
|
# setup logging
|
|
setup_logging()
|
|
# connect to minio
|
|
minio_client = connect()
|
|
# list images in bucket
|
|
BUCKET_NAME = 'visual-critical-discourse-analysis'
|
|
obj_list = minio_client.list_objects(
|
|
bucket_name=BUCKET_NAME,
|
|
)
|
|
# begin moving images
|
|
for obj in obj_list:
|
|
# get image from minio
|
|
buffer = get(
|
|
client=minio_client,
|
|
object_name=obj.object_name,
|
|
)
|
|
# convert data to image
|
|
image = Image.open(buffer)
|
|
# put image into minio subfolder
|
|
put_image(
|
|
client=minio_client,
|
|
image=image,
|
|
)
|