new changes

This commit is contained in:
M. A. Reza 2025-08-27 17:25:00 +03:30
parent 763b8f4e9d
commit 19570140a1
11 changed files with 91 additions and 19 deletions

View File

@ -1,18 +0,0 @@
import sys
from pathlib import Path
BASE_DIR = Path(__file__).resolve().parent
def boolean_to_emooji(bool_val, primary_emooji: bool):
if primary_emooji:
return "" if bool_val else ""
return "☑️" if bool_val else "✖️"
def confirm_exit_terminal():
user_input = input('\n\nType "q" to exit.\n')
if user_input != "q":
return confirm_exit_terminal()
else:
sys.exit()

View File

@ -6,4 +6,5 @@ readme = "README.md"
requires-python = ">=3.11"
dependencies = [
"openpyxl>=3.1.5",
"python-dotenv>=1.1.1",
]

7
utils/base_main.py Normal file
View File

@ -0,0 +1,7 @@
from pathlib import Path
from dotenv import load_dotenv
load_dotenv()
BASE_DIR = Path(__file__).resolve().parent

9
utils/common_utils.py Normal file
View File

@ -0,0 +1,9 @@
import sys
def confirm_exit_terminal():
user_input = input('\n\nType "q" to exit.\n')
if user_input != "q":
return confirm_exit_terminal()
else:
sys.exit()

50
utils/csv_utils.py Normal file
View File

@ -0,0 +1,50 @@
import csv
from pathlib import Path
def read_csv_file(file_path, parse_to_dict: bool = False):
with open(file_path, "r", newline="") as csvfile:
if parse_to_dict:
return list(csv.DictReader(csvfile))
else:
return list(csv.reader(csvfile))
def write_to_csv_file(rows, file_path: Path, rows_type, fieldnames=None):
file_path.parent.mkdir(parents=True, exist_ok=True)
with open(file_path, mode="w", newline="") as csvfile:
if rows_type is list:
csv_writer = csv.writer(csvfile)
return csv_writer.writerows(rows)
elif rows_type is dict:
csv_writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
csv_writer.writeheader()
csv_writer.writerows(rows)
else:
raise Exception("rows_type value is invalid!")
def append_to_csv_file(rows, file_path: Path):
file_path.parent.mkdir(parents=True, exist_ok=True)
with open(file_path, mode="a", newline="") as csvfile:
csv_writer = csv.writer(csvfile)
return csv_writer.writerows(rows)
def convert_config_to_key_val_dict(config: list):
res = dict()
for row in config:
match row["value_type"]:
case "int":
value = int(row["value"])
case _:
raise Exception("Invalid value_type.")
res[row["key"]] = value
return res
def convert_config_dict_to_list_of_key_values(config: dict):
result = list()
for k, v in config.items():
result.append({"key": k, "value": v, "value_type": type(v).__name__})
return result

6
utils/sequence_utils.py Normal file
View File

@ -0,0 +1,6 @@
import functools
import operator
def flatten_list(list_var):
return functools.reduce(operator.iconcat, list_var, [])

4
utils/string_utils.py Normal file
View File

@ -0,0 +1,4 @@
def boolean_to_emooji(bool_val, primary_emooji: bool):
if primary_emooji:
return "" if bool_val else ""
return "☑️" if bool_val else "✖️"

15
uv.lock generated
View File

@ -23,13 +23,26 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/c0/da/977ded879c29cbd04de313843e76868e6e13408a94ed6b987245dc7c8506/openpyxl-3.1.5-py2.py3-none-any.whl", hash = "sha256:5282c12b107bffeef825f4617dc029afaf41d0ea60823bbb665ef3079dc79de2", size = 250910, upload-time = "2024-06-28T14:03:41.161Z" },
]
[[package]]
name = "python-dotenv"
version = "1.1.1"
source = { registry = "https://pypi.org/simple" }
sdist = { url = "https://files.pythonhosted.org/packages/f6/b0/4bc07ccd3572a2f9df7e6782f52b0c6c90dcbb803ac4a167702d7d0dfe1e/python_dotenv-1.1.1.tar.gz", hash = "sha256:a8a6399716257f45be6a007360200409fce5cda2661e3dec71d23dc15f6189ab", size = 41978, upload-time = "2025-06-24T04:21:07.341Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/5f/ed/539768cf28c661b5b068d66d96a2f155c4971a5d55684a514c1a0e0dec2f/python_dotenv-1.1.1-py3-none-any.whl", hash = "sha256:31f23644fe2602f88ff55e1f5c79ba497e01224ee7737937930c448e4d0e24dc", size = 20556, upload-time = "2025-06-24T04:21:06.073Z" },
]
[[package]]
name = "python-utils"
version = "0.1.0"
source = { virtual = "." }
dependencies = [
{ name = "openpyxl" },
{ name = "python-dotenv" },
]
[package.metadata]
requires-dist = [{ name = "openpyxl", specifier = ">=3.1.5" }]
requires-dist = [
{ name = "openpyxl", specifier = ">=3.1.5" },
{ name = "python-dotenv", specifier = ">=1.1.1" },
]