-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add script to timestamp data files
- Loading branch information
Showing
3 changed files
with
25 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,7 +44,6 @@ build | |
eggs | ||
.eggs | ||
parts | ||
bin | ||
var | ||
sdist | ||
develop-eggs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env python | ||
|
||
import os | ||
import sys | ||
import datetime | ||
from pathlib import Path | ||
|
||
if len(sys.argv) < 2: | ||
print( | ||
"""pysm_tag_filename | ||
Modify a filename to add a datestamp based on the last modification date | ||
e.g. `myfile.txt` becomes `myfile_2022.06.22.txt`""" | ||
) | ||
|
||
for filename in sys.argv[1:]: | ||
filename = Path(filename) | ||
file_modification_date = datetime.datetime.fromtimestamp( | ||
os.path.getmtime(filename) | ||
).strftime("%Y.%m.%d") | ||
new_filename = f"{filename.stem}_{file_modification_date}{filename.suffix}" | ||
print(filename, "=>", new_filename) | ||
filename.rename(new_filename) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters