import os 
import zipfile
import boto3


current_directory = os.path.abspath(os.path.dirname(__file__))
parent_directory = os.path.abspath(os.path.join(current_directory, ".."))
data_directory = os.path.join(parent_directory, "data")
os.makedirs(data_directory, exist_ok=True)


if __name__ == "__main__":

	bucket_name = "ecos-ai-test-upload"

	aws_access_key_id = "AKIAZACAZYZZSLPRCNCD"

	aws_secret_access_key = "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"

	s3_client = boto3.client("s3",
		aws_access_key_id=aws_access_key_id,
		aws_secret_access_key=aws_secret_access_key
	)

	# NOTE: either "png", "jpg" or "txt"
	encode_type = "jpg"

	key = f"data/ichiwa/{encode_type}.zip"

	s3_client.download_file(bucket_name, key, 
	os.path.join(data_directory, f"{encode_type}.zip"))

	with zipfile.ZipFile(os.path.join(data_directory, f"{encode_type}.zip"), 'r') as zip_file:
		zip_file.extractall(data_directory)

	os.remove(os.path.join(data_directory, f"{encode_type}.zip"))

