Skip to content

Commit

Permalink
feat: add script to timestamp data files
Browse files Browse the repository at this point in the history
  • Loading branch information
zonca committed Dec 12, 2023
1 parent 694653e commit 83274c8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ build
eggs
.eggs
parts
bin
var
sdist
develop-eggs
Expand Down
23 changes: 23 additions & 0 deletions bin/pysm_tag_filename
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)
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ zip_safe = False
packages = find:
python_requires = >=3.7
setup_requires = setuptools_scm
scripts =
bin/pysm_tag_filename
install_requires =
healpy >= 1.16.0
numba
Expand Down

0 comments on commit 83274c8

Please sign in to comment.