Refactor
This commit is contained in:
parent
07cf7dee3c
commit
0683c98e6f
3 changed files with 21 additions and 29 deletions
|
|
@ -1,5 +1,6 @@
|
|||
"""Utility functions."""
|
||||
|
||||
import os
|
||||
from datetime import date, datetime, timezone
|
||||
|
||||
|
||||
|
|
@ -65,3 +66,14 @@ def filename_timestamp(filename: str, ext: str) -> tuple[datetime, str] | None:
|
|||
except ValueError:
|
||||
return None
|
||||
return (ts, filename)
|
||||
|
||||
|
||||
def get_most_recent_file(directory: str, ext: str) -> str | None:
|
||||
"""Get most recent file from directory."""
|
||||
existing = [
|
||||
x for x in (filename_timestamp(f, ext) for f in os.listdir(directory)) if x
|
||||
]
|
||||
if not existing:
|
||||
return None
|
||||
existing.sort(reverse=True)
|
||||
return os.path.join(directory, existing[0][1])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue