You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
2.5 KiB
Python
70 lines
2.5 KiB
Python
import os
|
|
from dataclasses import dataclass
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
load_dotenv()
|
|
|
|
GOOGLE_SCOPES = (
|
|
"https://www.googleapis.com/auth/gmail.modify",
|
|
"https://www.googleapis.com/auth/gmail.send",
|
|
"https://www.googleapis.com/auth/calendar.readonly",
|
|
)
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class Settings:
|
|
google_client_secrets_file: str
|
|
google_token_file: str
|
|
gmail_scan_interval_minutes: int
|
|
gmail_query: str
|
|
agent_api_key: str
|
|
llm_api_key: str
|
|
llm_model: str
|
|
llm_base_url: str | None
|
|
llm_timeout_seconds: float
|
|
llm_fallback_to_rules: bool
|
|
unsubscribe_digest_interval_minutes: int
|
|
unsubscribe_query: str
|
|
unsubscribe_max_results: int
|
|
unsubscribe_state_file: str
|
|
unsubscribe_digest_recipient: str | None
|
|
unsubscribe_send_empty_digest: bool
|
|
log_level: str
|
|
|
|
|
|
def get_settings() -> Settings:
|
|
llm_base_url = os.getenv("LLM_BASE_URL", "").strip()
|
|
unsubscribe_digest_recipient = os.getenv("UNSUBSCRIBE_DIGEST_RECIPIENT", "").strip()
|
|
return Settings(
|
|
google_client_secrets_file=os.getenv("GOOGLE_CLIENT_SECRETS_FILE", "credentials.json"),
|
|
google_token_file=os.getenv("GOOGLE_TOKEN_FILE", "token.json"),
|
|
gmail_scan_interval_minutes=int(os.getenv("GMAIL_SCAN_INTERVAL_MINUTES", "5")),
|
|
gmail_query=os.getenv(
|
|
"GMAIL_QUERY", "in:inbox -label:AgentProcessed newer_than:7d"
|
|
),
|
|
agent_api_key=os.getenv("AGENT_API_KEY", ""),
|
|
llm_api_key=os.getenv("LLM_API_KEY", ""),
|
|
llm_model=os.getenv("LLM_MODEL", "gpt-4.1-mini"),
|
|
llm_base_url=llm_base_url or None,
|
|
llm_timeout_seconds=float(os.getenv("LLM_TIMEOUT_SECONDS", "20")),
|
|
llm_fallback_to_rules=_as_bool(os.getenv("LLM_FALLBACK_TO_RULES", "false")),
|
|
unsubscribe_digest_interval_minutes=int(
|
|
os.getenv("UNSUBSCRIBE_DIGEST_INTERVAL_MINUTES", "1440")
|
|
),
|
|
unsubscribe_query=os.getenv("UNSUBSCRIBE_QUERY", "label:Advertising"),
|
|
unsubscribe_max_results=int(os.getenv("UNSUBSCRIBE_MAX_RESULTS", "500")),
|
|
unsubscribe_state_file=os.getenv(
|
|
"UNSUBSCRIBE_STATE_FILE", "data/sent_unsubscribe_links.json"
|
|
),
|
|
unsubscribe_digest_recipient=unsubscribe_digest_recipient or None,
|
|
unsubscribe_send_empty_digest=_as_bool(
|
|
os.getenv("UNSUBSCRIBE_SEND_EMPTY_DIGEST", "false")
|
|
),
|
|
log_level=os.getenv("LOG_LEVEL", "INFO"),
|
|
)
|
|
|
|
|
|
def _as_bool(value: str) -> bool:
|
|
return value.strip().lower() in {"1", "true", "yes", "on"}
|