feat: add a configuration flow

This commit is contained in:
2025-12-14 09:10:56 +01:00
parent 95f30954b5
commit 58661641d1

40
auditui/configure.py Normal file
View File

@@ -0,0 +1,40 @@
"""Configuration helpers for the Auditui app."""
from getpass import getpass
from pathlib import Path
from typing import Tuple
import audible
from .constants import AUTH_PATH
def configure(
auth_path: Path = AUTH_PATH,
) -> Tuple[audible.Authenticator, audible.Client]:
"""Force re-authentication and save credentials."""
if auth_path.exists():
response = input(
"Configuration already exists. Are you sure you want to overwrite it? (y/N): "
).strip().lower()
if response not in ("yes", "y"):
print("Configuration cancelled.")
raise SystemExit(0)
print("Please authenticate with your Audible account.")
email = input("\nEmail: ")
password = getpass("Password: ")
marketplace = input(
"Marketplace locale (default: US): ").strip().upper() or "US"
authenticator = audible.Authenticator.from_login(
username=email, password=password, locale=marketplace
)
auth_path.parent.mkdir(parents=True, exist_ok=True)
authenticator.to_file(str(auth_path))
print("Authentication successful!")
audible_client = audible.Client(auth=authenticator)
return authenticator, audible_client