Skip to content

Commit 26c41e0

Browse files
cleanup util
1 parent 472f5f1 commit 26c41e0

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

libs/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from re import ASCII
12
from typing import Final
23

34

@@ -157,3 +158,7 @@ class test_data_file_paths:
157158
CLASS_HEADER_ONLY: Final[str] = (
158159
f"test_data/class_list/i_header_only.csv{escape_characters.SEPARATOR}test_data/class_list/o_header_only.csv"
159160
)
161+
162+
163+
class file_encoding:
164+
ASCII = "ascii"

libs/wrappers.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import base64
2+
import os
13
import time
24
from datetime import datetime, timedelta
35

4-
from libs.constants import escape_characters
6+
from libs.constants import escape_characters, file_encoding
57

68

79
def convert_time_units_to_seconds(time_unit: str) -> int:
@@ -32,12 +34,12 @@ def wait(timeout: str):
3234

3335

3436
def get_link_formatted_date_time():
35-
_ampm = datetime.now().strftime(format="%p").lower()
37+
_am_or_pm = datetime.now().strftime(format="%p").lower()
3638
try:
3739
_dt = datetime.now().strftime(format="%-d %B %Y at %-I:%M") # Linux (Github Action)
3840
except:
3941
_dt = datetime.now().strftime(format="%#d %B %Y at %#I:%M") # Windows (Dev VDI)
40-
return f"{_dt}{_ampm}"
42+
return f"{_dt}{_am_or_pm}"
4143

4244

4345
def get_new_datetime() -> str:
@@ -62,3 +64,20 @@ def get_offset_date(offset_days: int) -> str:
6264
while _offset_date.weekday() >= 5:
6365
_offset_date = _offset_date + timedelta(days=1)
6466
return _offset_date.strftime("%Y%m%d")
67+
68+
69+
def get_project_root() -> str:
70+
_project_root = os.path.dirname(__file__)
71+
while os.path.basename(_project_root.lower()) != "manage-vaccinations-in-schools-testing":
72+
_project_root = os.path.dirname(_project_root)
73+
return _project_root
74+
75+
76+
def get_base64_encoded_string(text):
77+
text_bytes = text.encode(file_encoding.ASCII)
78+
return base64.b64encode(text_bytes).decode(file_encoding.ASCII)
79+
80+
81+
def get_base64_decoded_string(encoded_string):
82+
base64_bytes = encoded_string.encode(file_encoding.ASCII)
83+
return base64.b64decode(base64_bytes).decode(file_encoding.ASCII)

utils/001_cleanup.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import os
2+
3+
# This script is to be used manually before any commits in new code to avoid committing any reports or working files.
4+
folders_to_clean = ["working", "reports"]
5+
6+
7+
def cleanup() -> None:
8+
for _folder in folders_to_clean:
9+
_all_files = os.listdir(_folder)
10+
for _file in _all_files:
11+
if _file != ".gitkeep":
12+
os.remove(os.path.join(_folder, _file))
13+
14+
15+
if __name__ == "__main__":
16+
cleanup()

0 commit comments

Comments
 (0)