Update environment variable loading to support process environment and improve error handling
All checks were successful
Publish Twitch Archive Container / publish (push) Successful in 1m24s

Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
MaddoScientisto 2026-04-25 16:19:01 +02:00
commit cd3e37ff59
4 changed files with 34 additions and 12 deletions

View file

@ -137,7 +137,7 @@ class TwitchArchive:
def _load_environment_variables(self) -> None:
"""
Load environment variables from .env file.
Load environment variables from process environment or an optional .env file.
Required variables:
- CLIENT-ID: Twitch API client ID
@ -148,16 +148,26 @@ class TwitchArchive:
- PASSWD: Email password for sending notifications (if enabled)
Raises:
SystemExit: If .env file is not found
SystemExit: If required Twitch API credentials are unavailable
"""
has_required_env = bool(
get_env_value('CLIENT-ID', 'CLIENT_ID') and
get_env_value('CLIENT-SECRET', 'CLIENT_SECRET')
)
if has_required_env:
print(f'{Fore.GREEN}✓ Twitch API credentials loaded from process environment{Style.RESET_ALL}')
return
dotenv_loaded = load_dotenv(find_dotenv())
has_required_env = bool(
get_env_value('CLIENT-ID', 'CLIENT_ID') and
get_env_value('CLIENT-SECRET', 'CLIENT_SECRET')
)
if not dotenv_loaded and has_required_env:
print(f'{Fore.GREEN}✓ Twitch API credentials loaded from process environment{Style.RESET_ALL}')
if has_required_env:
if dotenv_loaded:
print(f'{Fore.GREEN}✓ Twitch API credentials loaded from .env file{Style.RESET_ALL}')
return
if not dotenv_loaded and not has_required_env: