Cat Feeder  1.0.0
The Cat feeder project
Loading...
Searching...
No Matches
mail_constants.py
Go to the documentation of this file.
1r"""
2# +==== BEGIN CatFeeder =================+
3# LOGO:
4# ..............(..../\
5# ...............)..(.')
6# ..............(../..)
7# ...............\‍(__)|
8# Inspired by Joan Stark
9# source https://www.asciiart.eu/
10# animals/cats
11# /STOP
12# PROJECT: CatFeeder
13# FILE: mail_constants.py
14# CREATION DATE: 18-11-2025
15# LAST Modified: 0:38:53 26-11-2025
16# DESCRIPTION:
17# This is the backend server in charge of making the actual website work.
18# /STOP
19# COPYRIGHT: (c) Cat Feeder
20# PURPOSE: The file in charge of containing the constants for the mail management class.
21# // AR
22# +==== END CatFeeder =================+
23"""
24
25import os
26from typing import Optional, Dict
27import dotenv
28from display_tty import Disp, initialise_logger
29IDISP: Disp = initialise_logger("mail_constants", False)
30
31# Environement initialisation
32dotenv.load_dotenv(".env")
33_DOTENV = dict(dotenv.dotenv_values())
34_OS_ENV = dict(os.environ)
35ENV = {}
36ENV.update(_OS_ENV)
37ENV.update(_DOTENV)
38
39
40def _get_environement_variable(environement: Dict[str, Optional[str]], variable_name: str) -> str:
41 """_summary_
42 Get the content of an environement variable.
43
44 Args:
45 variable_name (str): _description_
46
47 Returns:
48 str: _description_: the value of that variable, otherwise an exception is raised.
49 """
50 if environement is None:
51 raise ValueError(
52 "No environement file loaded."
53 )
54 data = environement.get(variable_name, None)
55 if data is None:
56 # required for expanding the variable name
57 error_msg = f"Variable {variable_name} not found in the environement"
58 raise ValueError(error_msg)
59 return data
60
61
62SENDER_ADDRESS: str = _get_environement_variable(ENV, "SENDER_ADDRESS")
63SENDER_HOST: str = _get_environement_variable(ENV, "SENDER_HOST")
64SENDER_KEY: str = _get_environement_variable(ENV, "SENDER_KEY")
65tmp: str = _get_environement_variable(ENV, "SENDER_PORT")
66try:
67 SENDER_PORT: int = int(tmp)
68except ValueError as e:
69 ERR_MSG: str = "Failed to retrieve the sender port as a number from the environement"
70 IDISP.log_error(f"{ERR_MSG}: {e}")
71 raise RuntimeError(ERR_MSG) from e
str _get_environement_variable(Dict[str, Optional[str]] environement, str variable_name)