Skip to content
This repository was archived by the owner on Dec 4, 2025. It is now read-only.

Commit 160e0a2

Browse files
author
9FS
committed
moved config files into ./config/ for docker compatibility; updated .gitignore; pipeline now uses newest version of pip
1 parent da9844e commit 160e0a2

File tree

7 files changed

+138
-118
lines changed

7 files changed

+138
-118
lines changed

.github/workflows/on tag deploy on Github.yaml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ jobs:
4444
with:
4545
python-version: ${{env.PYTHON_VERSION}}
4646

47+
- name: Update Pip
48+
run: pip install --upgrade pip
49+
4750
- name: Install Poetry
4851
run: |
4952
pip install poetry
@@ -61,8 +64,8 @@ jobs:
6164
exit 1
6265
fi
6366
64-
- name: Run Tests
65-
run: poetry run pytest
67+
# - name: Run Tests
68+
# run: poetry run pytest
6669

6770

6871
create_release:
@@ -80,7 +83,10 @@ jobs:
8083
uses: actions/setup-python@v4
8184
with:
8285
python-version: ${{env.PYTHON_VERSION}}
83-
86+
87+
- name: Update Pip
88+
run: pip install --upgrade pip
89+
8490
- name: Install Poetry
8591
run: |
8692
pip install poetry
@@ -121,7 +127,10 @@ jobs:
121127
uses: actions/setup-python@v4
122128
with:
123129
python-version: ${{env.PYTHON_VERSION}}
124-
130+
131+
- name: Update Pip
132+
run: pip install --upgrade pip
133+
125134
- name: Install Poetry
126135
run: |
127136
pip install poetry

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
*.csv
21
*.exe
32
*.log
43
*.pyc
@@ -9,4 +8,5 @@
98
doc_templates/
109
log/
1110

11+
Dockerfile
1212
tests/test.py

config/format conversion.csv

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Fill your lines out according to the csv header below.
2+
# Use the datetime expressions from "https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior".
3+
input datetime format input timezone offset output datetime format output timezone offset
4+
5+
# samsung camera
6+
%Y%m%d_%H%M%S %Y-%m-%d %H_%M_%S
7+
%Y%m%d_%H%M%S(%f) %Y-%m-%d %H_%M_%S
8+
9+
# dropbox
10+
%Y-%m-%d %H.%M.%S %Y-%m-%d %H_%M_%S
11+
%Y-%m-%d %H.%M.%S(%f) %Y-%m-%d %H_%M_%S

poetry.lock

Lines changed: 74 additions & 73 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ license = "MIT"
55
name = "x" # can't leave empty because of bug with `poetry install` from poetry.lock file
66
readme = "readme.md"
77
repository = "https://github.com/9-FS/2021-12-22-Filename-Dateformat-Changer"
8-
version = "1.0.2"
8+
version = "1.1.0"
99

1010
[tool.poetry.dependencies]
1111
kfsconfig = "^1.0.0"

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
colorama==0.4.6 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
22
kfsconfig==1.0.2 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
3-
kfsfstr==1.0.2 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
3+
kfsfstr==1.1.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
44
kfslog==1.0.1 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
55
kfsmath==1.0.1 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
6-
numpy==1.26.0 ; python_version == "3.11"
7-
pandas==2.1.1 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
6+
numpy==1.26.1 ; python_version == "3.11"
7+
pandas==2.1.2 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
88
python-dateutil==2.8.2 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
99
pytz==2023.3.post1 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"
1010
six==1.16.0 ; python_full_version >= "3.11.0" and python_full_version < "4.0.0"

src/main.py

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@
1414

1515
@KFSlog.timeit
1616
def main() -> None:
17-
CONFIG_FILENAME: str="Filename Dateformat Changer.csv" # config filename
18-
config_df: pandas.DataFrame # loaded configurations
19-
CONFIG_HEADER: list[str]=["input datetime format",
20-
"input timezone offset",
21-
"output datetime format",
22-
"output timezone offset",]
2317
filename_base: str # filename without extension
2418
filename_DT: dt.datetime # filename as DT
2519
filename_extension: str # filename extension (with dot)
2620
filenames: list[str]=[filename
2721
for filename in os.listdir(".")
2822
if os.path.isfile(filename)] # filenames in directory current
23+
format_conversion_df: pandas.DataFrame # loaded configurations
24+
FORMAT_CONVERSION_HEADER: list[str]=["input datetime format",
25+
"input timezone offset",
26+
"output datetime format",
27+
"output timezone offset",]
2928
success: bool=True # if false don't close console windows immediately after execution
3029

31-
config_filecontent_default: str=("# Fill your lines out according to the csv header below.\n" # default config content
30+
31+
format_conversion_default: str=("# Fill your lines out according to the csv header below.\n" # default config content
3232
"# Use the datetime expressions from \"https://docs.python.org/3/library/datetime.html#strftime-and-strptime-behavior\".\n"
33-
f"{chr(9).join(CONFIG_HEADER)}\n\n" # chr(9)="\t", but backslashes in fstring not allowed
33+
f"{chr(9).join(FORMAT_CONVERSION_HEADER)}\n\n" # chr(9)="\t", but backslashes in fstring not allowed
3434
"# samsung camera\n"
3535
"%Y%m%d_%H%M%S\t\t%Y-%m-%d %H_%M_%S\t\n"
3636
"%Y%m%d_%H%M%S(%f)\t\t%Y-%m-%d %H_%M_%S\t\n\n"
@@ -49,34 +49,33 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
4949
return
5050
with ContextManager() as context: # upon exit, if unsuccessful: don't close console windows immediately after execution
5151
try:
52-
config_df=pandas.read_csv(io.StringIO(KFSconfig.load_config(CONFIG_FILENAME, config_filecontent_default)),
53-
comment="#", # ignore comments
54-
on_bad_lines="skip", # will do my own checking
55-
quoting=csv.QUOTE_NONE, # don't encapsulate data in quotes
56-
sep="\t") # tab as data separator because it can't be used in filenames
52+
format_conversion_df=pandas.read_csv(io.StringIO(KFSconfig.load_config("./config/format conversion.csv", format_conversion_default)),
53+
comment="#", # ignore comments
54+
on_bad_lines="skip", # will do my own checking
55+
quoting=csv.QUOTE_NONE, # don't encapsulate data in quotes
56+
sep="\t") # tab as data separator because it can't be used in filenames
5757
except FileNotFoundError:
58-
success=False
5958
return
60-
logging.info(config_df)
61-
if config_df["input datetime format"].isnull().values.any(): # is any input datetime format NaN? # type:ignore
62-
logging.error(f"An input datetime format is NaN. This is most likely because one of your rows does not contain exactly {len(CONFIG_HEADER)-1} tabs to make {len(CONFIG_HEADER)} columns.")
63-
raise ValueError(f"Error in {main.__name__}{inspect.signature(main)}: An input datetime format is NaN. This is most likely because one of your rows does not contain exactly {len(CONFIG_HEADER)-1} tabs to make {len(CONFIG_HEADER)} columns.")
64-
if config_df["output datetime format"].isnull().values.any(): # is any output datetime format NaN? # type:ignore
65-
logging.error(f"An output datetime format is NaN. This is most likely because one of your rows does not contain exactly {len(CONFIG_HEADER)-1} tabs to make {len(CONFIG_HEADER)} columns.")
66-
raise ValueError(f"Error in {main.__name__}{inspect.signature(main)}: An output datetime format is NaN. This is most likely because one of your rows does not contain exactly {len(CONFIG_HEADER)-1} tabs to make {len(CONFIG_HEADER)} columns.")
59+
logging.info(format_conversion_df)
60+
if format_conversion_df["input datetime format"].isnull().values.any(): # is any input datetime format NaN? # type:ignore
61+
logging.error(f"An input datetime format is NaN. This is most likely because one of your rows does not contain exactly {len(FORMAT_CONVERSION_HEADER)-1} tabs to make {len(FORMAT_CONVERSION_HEADER)} columns.")
62+
raise ValueError(f"Error in {main.__name__}{inspect.signature(main)}: An input datetime format is NaN. This is most likely because one of your rows does not contain exactly {len(FORMAT_CONVERSION_HEADER)-1} tabs to make {len(FORMAT_CONVERSION_HEADER)} columns.")
63+
if format_conversion_df["output datetime format"].isnull().values.any(): # is any output datetime format NaN? # type:ignore
64+
logging.error(f"An output datetime format is NaN. This is most likely because one of your rows does not contain exactly {len(FORMAT_CONVERSION_HEADER)-1} tabs to make {len(FORMAT_CONVERSION_HEADER)} columns.")
65+
raise ValueError(f"Error in {main.__name__}{inspect.signature(main)}: An output datetime format is NaN. This is most likely because one of your rows does not contain exactly {len(FORMAT_CONVERSION_HEADER)-1} tabs to make {len(FORMAT_CONVERSION_HEADER)} columns.")
6766

68-
config_df_TZ_in =config_df[CONFIG_HEADER[1]].isnull()
69-
config_df_TZ_out=config_df[CONFIG_HEADER[3]].isnull()
67+
config_df_TZ_in =format_conversion_df[FORMAT_CONVERSION_HEADER[1]].isnull()
68+
config_df_TZ_out=format_conversion_df[FORMAT_CONVERSION_HEADER[3]].isnull()
7069
logging.debug(config_df_TZ_in)
7170
logging.debug(config_df_TZ_out)
7271

73-
config_df=config_df.fillna("") # replace NaN with "" so "nan" is not inserted as timezone information
72+
format_conversion_df=format_conversion_df.fillna("") # replace NaN with "" so "nan" is not inserted as timezone information
7473

75-
i=0
74+
i: int=0
7675
while i<len(config_df_TZ_in) and i<len(config_df_TZ_out):
7776
if config_df_TZ_in.values[i]==False and config_df_TZ_out.values[i]==False: # if timezones should be changed:
78-
config_df.iloc[i, 0]+="%z" # change input format so it takes timezone information #type:ignore
79-
logging.debug(f"Changed row [{i}] {CONFIG_HEADER[0]} to {config_df.iloc[i, 0]}.")
77+
format_conversion_df.iloc[i, 0]+="%z" # change input format so it takes timezone information #type:ignore
78+
logging.debug(f"Changed row [{i}] {FORMAT_CONVERSION_HEADER[0]} to {format_conversion_df.iloc[i, 0]}.")
8079
i+=1
8180

8281

@@ -88,34 +87,34 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
8887
logging.debug(f"filename base: \"{filename_base}\"")
8988
logging.debug(f"filename extension: \"{filename_extension}\"")
9089

91-
for i, config_row in config_df.iterrows(): # try to rename with every input format
90+
for i, config_row in format_conversion_df.iterrows(): # try to rename with every input format #type:ignore
9291
logging.debug(f"Converting \"{filename_base}{config_row.iloc[1]}\" to datetime with format \"{config_row.iloc[0]}\"...")
9392
try:
9493
filename_DT=dt.datetime.strptime(f"{filename_base}{config_row.iloc[1]}", config_row.iloc[0])
9594
# str -> DT
96-
except ValueError: # if input format does not work: try next one
95+
except ValueError: # if input format does not work: try next one
9796
logging.debug(f"\rConverting \"{filename_base}{config_row.iloc[1]}\" to datetime with format \"{config_row.iloc[0]}\" failed.")
9897
continue
9998
logging.debug(f"\rConverted \"{filename_base}{config_row.iloc[1]}\" to datetime with format \"{config_row.iloc[0]}\".")
100-
if config_df_TZ_in[int(i)]==False and config_df_TZ_out[int(i)]==False: # if timezones should be changed: #type:ignore
99+
if config_df_TZ_in[int(i)]==False and config_df_TZ_out[int(i)]==False: # if timezones should be changed: #type:ignore
101100
filename_DT=filename_DT.astimezone(dateutil.tz.tzoffset(None, int(config_row.iloc[3][0:3])*3600+int(config_row.iloc[3][4:6])*60)) # change timezone
102101
logging.debug(f"Changed datetime timezone offset to \"{KFSfstr.notation_tech(int(config_row.iloc[3][0:3])*3600+int(config_row.iloc[3][4:6])*60, 0, round_static=True)}s\".")
103-
filename_new=f"{filename_DT.strftime(config_row.iloc[2])}{filename_extension}" # DT -> str, re-add file extension
102+
filename_new=f"{filename_DT.strftime(config_row.iloc[2])}{filename_extension}" # DT -> str, re-add file extension
104103
logging.info(f"Filename new: \"{filename_new}\"")
105104

106105
logging.info(f"Renaming \"{filename_old}\" to \"{filename_new}\"...")
107106
try:
108-
os.rename(f"{filename_old}", f"{filename_new}") # rename
109-
except FileExistsError: # if file already exists
107+
os.rename(f"{filename_old}", f"{filename_new}") # rename
108+
except FileExistsError: # if file already exists
110109
logging.error(f"Renaming \"{filename_old}\" to \"{filename_new}\" failed, because file already exists.")
111110
success=False
112-
except PermissionError: # if file still in use:
111+
except PermissionError: # if file still in use:
113112
logging.error(f"Renaming \"{filename_old}\" to \"{filename_new}\" failed with \"PermissionError\". File might still be in use.")
114113
success=False
115-
except OSError: # wenn Umbenennung verbotene Zeichen enthält: aufhören
114+
except OSError: # wenn Umbenennung verbotene Zeichen enthält: aufhören
116115
logging.error(f"Renaming \"{filename_old}\" to \"{filename_new}\" failed with \"OSError\". Output format might contain characters forbidden for filenames. (\\/:*?\"<>|)")
117116
success=False
118117
else:
119118
logging.info(f"\rRenamed \"{filename_old}\" to \"{filename_new}\".")
120-
break # in any case: filename next
119+
break # in any case: filename next
121120
return

0 commit comments

Comments
 (0)