Skip to content

Commit

Permalink
adds function that lists files send to s3 in the last two weeks
Browse files Browse the repository at this point in the history
  • Loading branch information
niquerio committed Jan 9, 2025
1 parent 4a7b183 commit 34df42a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
16 changes: 16 additions & 0 deletions aim/digifeeds/functions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from aim.services import S
import boto3
from pathlib import Path
from rclone_python import rclone
from datetime import datetime


def list_barcodes_in_input_bucket():
Expand All @@ -13,3 +15,17 @@ def list_barcodes_in_input_bucket():
response = s3.list_objects_v2(Bucket=S.digifeeds_s3_bucket, Prefix=prefix)
barcodes = [Path(object["Key"]).stem for object in response["Contents"]]
return barcodes


def barcodes_added_in_last_two_weeks():
files = rclone.ls(
path=f"{S.digifeeds_s3_rclone_remote}:{S.digifeeds_s3_input_path}",
args=["--max-age 14d"],
)
output = []
for file in files:
barcode = file["Name"].split(".")[0]
date = datetime.fromisoformat(file["ModTime"]).strftime("%Y-%m-%d")
output.append([date, barcode])

return output
33 changes: 33 additions & 0 deletions tests/digifeeds/test_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import json
from aim.digifeeds.functions import rclone, barcodes_added_in_last_two_weeks


def test_barcodes_added_in_last_two_weeks(mocker):
ls_data_raw = """
[
{
"Path": "35112203951670.zip",
"Name": "35112203951670.zip",
"Size": 554562627,
"MimeType": "application/zip",
"ModTime": "2024-12-14T02:01:05.093051502-05:00",
"IsDir": false,
"Tier": "STANDARD"
},
{
"Path": "39015004707009.zip",
"Name": "39015004707009.zip",
"Size": 232895588,
"MimeType": "application/zip",
"ModTime": "2024-12-14T02:02:29.111076546-05:00",
"IsDir": false,
"Tier": "STANDARD"
}
]
"""
mocker.patch.object(rclone, "ls", return_value=json.loads(ls_data_raw))
output = barcodes_added_in_last_two_weeks()
assert output == [
["2024-12-14", "35112203951670"],
["2024-12-14", "39015004707009"],
]

0 comments on commit 34df42a

Please sign in to comment.