Skip to content

Module config

get_DB_VARS()

Retrieve the database configuration variables from the environment.

This function loads the environment variables and retrieves the following database configuration variables: - DB_HOST: The hostname for the database. - DB_NAME: The name of the database. - DB_LOGS: A flag indicating if logging is enabled.

Returns:

Type Description
Tuple[Optional[str], Optional[str], Optional[str]]

Tuple[Optional[str], Optional[str], Optional[str]]: A tuple containing (DB_HOST, DB_NAME, DB_LOGS).

Source code in nbs/config.py
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
def get_DB_VARS() -> Tuple[Optional[str], Optional[str], Optional[str]]:
    """Retrieve the database configuration variables from the environment.

    This function loads the environment variables and retrieves the following
    database configuration variables:
        - DB_HOST: The hostname for the database.
        - DB_NAME: The name of the database.
        - DB_LOGS: A flag indicating if logging is enabled.

    Returns:
        Tuple[Optional[str], Optional[str], Optional[str]]:
            A tuple containing (DB_HOST, DB_NAME, DB_LOGS).
    """
    load_env()
    DB_HOST: Optional[str] = os.getenv("DB_HOST")
    DB_NAME: Optional[str] = os.getenv("DB_NAME")
    DB_LOGS: Optional[str] = os.getenv("DB_LOGS")
    return DB_HOST, DB_NAME, DB_LOGS

get_RSS_URL()

Récupère l'URL du flux RSS à partir des variables d'environnement.

Returns:

Name Type Description
str str

L'URL du flux RSS. Si la variable d'environnement RSS_LMELP_URL n'est pas définie,

str

retourne une URL par défaut.

Source code in nbs/config.py
32
33
34
35
36
37
38
39
40
41
42
43
44
def get_RSS_URL() -> str:
    """
    Récupère l'URL du flux RSS à partir des variables d'environnement.

    Returns:
        str: L'URL du flux RSS. Si la variable d'environnement `RSS_LMELP_URL` n'est pas définie,
        retourne une URL par défaut.
    """
    load_env()
    RSS_LMELP_URL = os.getenv("RSS_LMELP_URL")
    if RSS_LMELP_URL is None:
        RSS_LMELP_URL = "https://radiofrance-podcast.net/podcast09/rss_14007.xml"
    return RSS_LMELP_URL

get_WEB_filename()

Get the filename of the WEB_LMELP file.

This function loads environment variables and retrieves the value of the WEB_LMELP_FILENAME environment variable. If the variable is not set, it returns a default file path.

Returns:

Name Type Description
str str

The filename of the WEB_LMELP file.

Source code in nbs/config.py
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
def get_WEB_filename() -> str:
    """
    Get the filename of the WEB_LMELP file.

    This function loads environment variables and retrieves the value of the
    `WEB_LMELP_FILENAME` environment variable. If the variable is not set,
    it returns a default file path.

    Returns:
        str: The filename of the WEB_LMELP file.
    """
    load_env()

    WEB_LMELP_FILENAME = os.getenv("WEB_LMELP_FILENAME")
    if WEB_LMELP_FILENAME is None:
        WEB_LMELP_FILENAME = "db/À écouter plus tard I Radio France/À écouter plus tard I Radio France.html"

    return str(Path(get_git_root(""), WEB_LMELP_FILENAME))

get_audio_path(audio_path=AUDIO_PATH, year='2024')

Returns the full path to the audio files by appending the year as a subdirectory.

If the directory does not exist, it is created.

Parameters:

Name Type Description Default
audio_path str

Relative path to the audio files.

AUDIO_PATH
year str

The year used as a subdirectory (default "2024").

'2024'

Returns:

Name Type Description
str str

The full path to the corresponding audio directory.

Example

path = get_audio_path("audios", "2024")

Source code in nbs/config.py
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
def get_audio_path(audio_path: str = AUDIO_PATH, year: str = "2024") -> str:
    """Returns the full path to the audio files by appending the year as a subdirectory.

    If the directory does not exist, it is created.

    Args:
        audio_path (str): Relative path to the audio files.
        year (str): The year used as a subdirectory (default "2024").

    Returns:
        str: The full path to the corresponding audio directory.

    Example:
        >>> path = get_audio_path("audios", "2024")
    """

    project_root: str = get_git_root(os.getcwd())
    full_audio_path: str = os.path.join(project_root, audio_path, year)

    # Create the directory if it does not exist
    if not os.path.exists(full_audio_path):
        os.makedirs(full_audio_path)

    return full_audio_path

get_azure_openai_keys()

Get the Azure OpenAI keys from environment variables.

Returns:

Name Type Description
tuple tuple[str, str, str]

A tuple containing the Azure API key, endpoint, and API version.

Source code in nbs/config.py
 96
 97
 98
 99
100
101
102
103
104
105
106
107
def get_azure_openai_keys() -> tuple[str, str, str]:
    """
    Get the Azure OpenAI keys from environment variables.

    Returns:
        tuple: A tuple containing the Azure API key, endpoint, and API version.
    """
    load_env()
    azure_api_key = os.getenv("AZURE_API_KEY")
    azure_endpoint = os.getenv("AZURE_ENDPOINT")
    azure_api_version = os.getenv("AZURE_API_VERSION")
    return azure_api_key, azure_endpoint, azure_api_version

get_gemini_api_key()

Get the Gemini API key from environment variables.

Returns:

Name Type Description
str str

The Gemini API key.

Source code in nbs/config.py
48
49
50
51
52
53
54
55
56
57
def get_gemini_api_key() -> str:
    """
    Get the Gemini API key from environment variables.

    Returns:
        str: The Gemini API key.
    """
    load_env()
    gemini_api_key = os.getenv("GEMINI_API_KEY")
    return gemini_api_key

get_git_root(path)

Retrieves the root directory of the Git repository.

Parameters:

Name Type Description Default
path str

The current working directory.

required

Returns:

Name Type Description
str str

The root directory of the Git repository.

Source code in nbs/config.py
114
115
116
117
118
119
120
121
122
123
124
def get_git_root(path: str) -> str:
    """Retrieves the root directory of the Git repository.

    Args:
        path (str): The current working directory.

    Returns:
        str: The root directory of the Git repository.
    """
    git_repo = Repo(path, search_parent_directories=True)
    return git_repo.git.rev_parse("--show-toplevel")

get_google_auth_file()

Get the Google authentication file path from environment variables.

Returns:

Name Type Description
str str

The path to the Google authentication file.

Source code in nbs/config.py
84
85
86
87
88
89
90
91
92
93
def get_google_auth_file() -> str:
    """
    Get the Google authentication file path from environment variables.

    Returns:
        str: The path to the Google authentication file.
    """
    load_env()
    google_auth_file = os.getenv("GOOGLE_AUTH_FILE")
    return google_auth_file

get_google_projectID()

Get the Google Project ID from environment variables.

Returns:

Name Type Description
str str

The Google Project ID.

Source code in nbs/config.py
72
73
74
75
76
77
78
79
80
81
def get_google_projectID() -> str:
    """
    Get the Google Project ID from environment variables.

    Returns:
        str: The Google Project ID.
    """
    load_env()
    google_projectID = os.getenv("GOOGLE_PROJECT_ID")
    return google_projectID

get_openai_api_key()

Get the OpenAI API key from environment variables.

Returns:

Name Type Description
str str

The OpenAI API key.

Source code in nbs/config.py
60
61
62
63
64
65
66
67
68
69
def get_openai_api_key() -> str:
    """
    Get the OpenAI API key from environment variables.

    Returns:
        str: The OpenAI API key.
    """
    load_env()
    openai_api_key = os.getenv("OPENAI_API_KEY")
    return openai_api_key

load_env()

Charge les variables d'environnement à partir d'un fichier .env.

Source code in nbs/config.py
24
25
26
27
28
def load_env() -> None:
    """
    Charge les variables d'environnement à partir d'un fichier .env.
    """
    _ = load_dotenv(find_dotenv())