Skip to content

Commit

Permalink
assumes s3 bucket has zip files when listing barcodes
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Oct 31, 2024
1 parent 7665ce4 commit b730821
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 3 additions & 7 deletions aim/digifeeds/list_barcodes_in_bucket.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import boto3
from aim.services import S
from pathlib import Path


def list_barcodes_in_bucket():
Expand All @@ -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
4 changes: 2 additions & 2 deletions tests/digifeeds/test_list_barcodes_in_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit b730821

Please sign in to comment.