-
-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add: get metadata dict from s3 bucket with last modified date and siz… #69
Changes from 1 commit
00ceeeb
da8fc46
3c6c03d
b98b139
8e3da88
e343eef
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ class S3Bucket: | |
aws_access_key_id='my_access_key_id', | ||
aws_secret_key='my_secret_key' | ||
) | ||
|
||
NOTE: credentials should never be in the code. | ||
|
||
To upload a file to the bucket, use: | ||
|
@@ -133,3 +133,28 @@ def get_file_metadata(self, object_key): | |
obj = self.bucket.Object(object_key) | ||
metadata = obj.metadata | ||
return metadata | ||
|
||
def get_files_metadata(self, pattern=None): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would you mind adding type annotations? 🙏 Pattern explanation 👈In Python, type annotations are not enforced. But that can be valuable for debugging using mypy, for your collaborators' understanding, and the autocomplete of your IDE. For more details, feel free to check this resource.Code exampleHere is an example of how this is typically handled: # def is_upper(variable_name):
def is_upper(variable_name: str) -> bool: Quack feedback loop 👍👎This comment is about [missing-type-annotations]. Add the following reactions on this comment to let us know if:- 👍 that comment was on point - 👀 that doesn't seem right - 👎 this isn't important for you right now - 😕 that explanation wasn't clear |
||
""" | ||
Lists files in the S3 bucket with their size in GB and last modified dates. | ||
|
||
Args: | ||
pattern (str): The pattern to filter files by (optional). | ||
|
||
Returns: | ||
A dictionnary of file keys (paths), file sizes en GB and last modified dates in the bucket. | ||
""" | ||
files = [] | ||
for obj in self.bucket.objects.all(): | ||
if not pattern or pattern in obj.key: | ||
file_name = obj.key | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't look like we need this intermediate variable Pattern explanation 👈You shouldn't concede readability, but when it's possible, avoid unnecessary memory allocation. For more details, feel free to check this resource.Code exampleHere is an example of how this is typically handled: # def make_upper(input_str: str) -> str:
# upper_str = input_str.upper()
# return upper_str
def make_upper(input_str: str) -> str:
return input_str.upper() Quack feedback loop 👍👎This comment is about [intermediate-variable]. Add the following reactions on this comment to let us know if:- 👍 that comment was on point - 👀 that doesn't seem right - 👎 this isn't important for you right now - 😕 that explanation wasn't clear |
||
file_size = round(obj.size * 1.0 / (1024*1000000), 2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't look like we need this intermediate variable Pattern explanation 👈You shouldn't concede readability, but when it's possible, avoid unnecessary memory allocation. For more details, feel free to check this resource.Code exampleHere is an example of how this is typically handled: # def make_upper(input_str: str) -> str:
# upper_str = input_str.upper()
# return upper_str
def make_upper(input_str: str) -> str:
return input_str.upper() Quack feedback loop 👍👎This comment is about [intermediate-variable]. Add the following reactions on this comment to let us know if:- 👍 that comment was on point - 👀 that doesn't seem right - 👎 this isn't important for you right now - 😕 that explanation wasn't clear |
||
file_last_modified = obj.last_modified | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't look like we need this intermediate variable Pattern explanation 👈You shouldn't concede readability, but when it's possible, avoid unnecessary memory allocation. For more details, feel free to check this resource.Code exampleHere is an example of how this is typically handled: # def make_upper(input_str: str) -> str:
# upper_str = input_str.upper()
# return upper_str
def make_upper(input_str: str) -> str:
return input_str.upper() Quack feedback loop 👍👎This comment is about [intermediate-variable]. Add the following reactions on this comment to let us know if:- 👍 that comment was on point - 👀 that doesn't seem right - 👎 this isn't important for you right now - 😕 that explanation wasn't clear |
||
files.append( | ||
{ | ||
"file_name": file_name, | ||
"file_size": file_size, | ||
"file_last_modified": file_last_modified, | ||
} | ||
) | ||
return files |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you mind adding type annotations? 🙏
Pattern explanation 👈
In Python, type annotations are not enforced. But that can be valuable for debugging using mypy, for your collaborators' understanding, and the autocomplete of your IDE. For more details, feel free to check this resource.Code example
Here is an example of how this is typically handled:
Quack feedback loop 👍👎
This comment is about [missing-type-annotations]. Add the following reactions on this comment to let us know if:- 👍 that comment was on point
- 👀 that doesn't seem right
- 👎 this isn't important for you right now
- 😕 that explanation wasn't clear