Adding some comments, editing methods names

This commit is contained in:
adator85
2025-08-15 15:47:01 +02:00
parent 21a2619f49
commit 6b22d786e3
25 changed files with 344 additions and 233 deletions

View File

@@ -1,28 +1,24 @@
import sys
import importlib
from types import ModuleType
from typing import Literal, Union
from pathlib import Path
from typing import Literal, Optional, Any
from datetime import datetime
from time import time
from random import choice
from hashlib import md5, sha3_512
def convert_to_int(value: any) -> Union[int, None]:
def convert_to_int(value: Any) -> Optional[int]:
"""Convert a value to int
Args:
value (any): Value to convert to int if possible
value (Any): Value to convert to int if possible
Returns:
Union[int, None]: Return the int value or None if not possible
int: Return the int value or None if not possible
"""
try:
value_to_int = int(value)
return value_to_int
except ValueError:
return None
except Exception:
return None
def get_unixtime() -> int:
"""Cette fonction retourne un UNIXTIME de type 12365456
@@ -32,7 +28,7 @@ def get_unixtime() -> int:
"""
return int(time())
def get_datetime() -> str:
def get_sdatetime() -> str:
"""Retourne une date au format string (24-12-2023 20:50:59)
Returns:
@@ -41,6 +37,12 @@ def get_datetime() -> str:
currentdate = datetime.now().strftime('%d-%m-%Y %H:%M:%S')
return currentdate
def get_datetime() -> datetime:
"""
Return the current datetime in a datetime object
"""
return datetime.now()
def generate_random_string(lenght: int) -> str:
"""Retourn une chaîne aléatoire en fonction de la longueur spécifiée.
@@ -52,15 +54,15 @@ def generate_random_string(lenght: int) -> str:
return randomize
def hash(password: str, algorithm: Literal["md5, sha3_512"] = 'md5') -> str:
"""Retourne un mot de passe chiffré en fonction de l'algorithme utilisé
def hash_password(password: str, algorithm: Literal["md5, sha3_512"] = 'md5') -> str:
"""Return the crypted password following the selected algorithm
Args:
password (str): Le password en clair
algorithm (str): L'algorithm a utilisé
password (str): The plain text password
algorithm (str): The algorithm to use
Returns:
str: Le password haché
str: The crypted password, default md5
"""
match algorithm:
@@ -75,3 +77,13 @@ def hash(password: str, algorithm: Literal["md5, sha3_512"] = 'md5') -> str:
case _:
password = md5(password.encode()).hexdigest()
return password
def get_all_modules() -> list[str]:
"""Get list of all main modules
using this pattern mod_*.py
Returns:
list[str]: List of module names.
"""
base_path = Path('mods')
return [file.name.replace('.py', '') for file in base_path.rglob('mod_*.py')]