script to move images to subfolder in minio
This commit is contained in:
@@ -0,0 +1,39 @@
|
|||||||
|
"""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 as connect_minio
|
||||||
|
from shared.data_store import 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_minio(bucket='images')
|
||||||
|
# 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,
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user