From b7308218f3185d7d484440d1b66352f82ede1a63 Mon Sep 17 00:00:00 2001 From: Monique Rio Date: Thu, 31 Oct 2024 13:57:46 +0000 Subject: [PATCH] assumes s3 bucket has zip files when listing barcodes --- aim/digifeeds/list_barcodes_in_bucket.py | 10 +++------- tests/digifeeds/test_list_barcodes_in_bucket.py | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/aim/digifeeds/list_barcodes_in_bucket.py b/aim/digifeeds/list_barcodes_in_bucket.py index 61bcb80..18002ce 100644 --- a/aim/digifeeds/list_barcodes_in_bucket.py +++ b/aim/digifeeds/list_barcodes_in_bucket.py @@ -1,5 +1,6 @@ import boto3 from aim.services import S +from pathlib import Path def list_barcodes_in_bucket(): @@ -9,11 +10,6 @@ def list_barcodes_in_bucket(): aws_secret_access_key=S.digifeeds_s3_secret_access_key, ) prefix = S.digifeeds_s3_input_path + "/" - response = s3.list_objects_v2( - Bucket=S.digifeeds_s3_bucket, - Prefix=prefix, - Delimiter="/", - ) - paths = [object["Prefix"] for object in response["CommonPrefixes"]] - barcodes = [path.split("/")[1] for path in paths] + response = s3.list_objects_v2(Bucket=S.digifeeds_s3_bucket, Prefix=prefix) + barcodes = [Path(object["Key"]).stem for object in response["Contents"]] return barcodes diff --git a/tests/digifeeds/test_list_barcodes_in_bucket.py b/tests/digifeeds/test_list_barcodes_in_bucket.py index 299fafb..f44fb8f 100644 --- a/tests/digifeeds/test_list_barcodes_in_bucket.py +++ b/tests/digifeeds/test_list_barcodes_in_bucket.py @@ -14,11 +14,11 @@ def test_list_barcodes_in_bucket(): conn.create_bucket(Bucket=S.digifeeds_s3_bucket) barcode1 = conn.Object( - S.digifeeds_s3_bucket, f"{S.digifeeds_s3_input_path}/barcode1/some_file.txt" + S.digifeeds_s3_bucket, f"{S.digifeeds_s3_input_path}/barcode1.zip" ) barcode1.put(Body="some text") barcode2 = conn.Object( - S.digifeeds_s3_bucket, f"{S.digifeeds_s3_input_path}/barcode2/some_file.txt" + S.digifeeds_s3_bucket, f"{S.digifeeds_s3_input_path}/barcode2.zip" ) barcode2.put(Body="some text")