-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
41 lines (31 loc) · 1.29 KB
/
Copy pathconfig.py
File metadata and controls
41 lines (31 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
config.py
Handles application configuration, including loading the OMDb API key
from environment variables. This module NEVER hard-codes the API key;
it is loaded at runtime from a local .env file (via python-dotenv) or
from the actual system environment.
"""
import os
from dotenv import load_dotenv
# Load variables from a local .env file, if one exists.
# In production/deployment, environment variables can be set directly
# on the system instead of using a .env file.
load_dotenv()
# The OMDb API key, read from the environment. This will be None if the
# variable has not been set, which the rest of the application must
# handle gracefully (see api_client.py).
OMDB_API_KEY: str | None = os.getenv("OMDB_API_KEY")
# Base URL for the OMDb API.
OMDB_BASE_URL: str = "https://www.omdbapi.com/"
# Default request timeout, in seconds, for all outgoing HTTP requests.
REQUEST_TIMEOUT: int = 10
# Path to the local JSON file used to store favorite movies.
FAVORITES_FILE_PATH: str = os.path.join("data", "favorites.json")
def is_api_key_configured() -> bool:
"""
Check whether the OMDb API key has been configured.
Returns:
bool: True if the API key environment variable is set and
non-empty, False otherwise.
"""
return bool(OMDB_API_KEY and OMDB_API_KEY.strip())