185 lines
6.0 KiB
Python
185 lines
6.0 KiB
Python
"""
|
|
Configuration settings for eamco_address_checker.
|
|
|
|
This module provides configuration with environment-based switching:
|
|
- DEVELOPMENT: Uses 'eamco' database, localhost CORS origins
|
|
- PRODUCTION: Uses 'auburnoil' database, production domain CORS origins
|
|
|
|
Environment variables are loaded from .env.local or .env.prod depending
|
|
on the Docker compose file used.
|
|
"""
|
|
|
|
import os
|
|
from typing import List
|
|
|
|
from dotenv import load_dotenv
|
|
|
|
# Load environment variables from .env file if present
|
|
load_dotenv()
|
|
|
|
# =============================================================================
|
|
# ENVIRONMENT MODE
|
|
# =============================================================================
|
|
|
|
MODE = os.getenv("MODE", "LOCAL")
|
|
CURRENT_SETTINGS = os.getenv("CURRENT_SETTINGS", "DEVELOPMENT")
|
|
|
|
if CURRENT_SETTINGS == "PRODUCTION":
|
|
print("USING PRODUCTION APPLICATIONCONFIG!!!!!")
|
|
else:
|
|
print("USING DEVELOPMENT APPLICATIONCONFIG!!!!!")
|
|
|
|
# =============================================================================
|
|
# DATABASE CONFIGURATION
|
|
# =============================================================================
|
|
|
|
# Database connection components (can be overridden individually)
|
|
POSTGRES_USERNAME = os.getenv("POSTGRES_USERNAME", "postgres")
|
|
POSTGRES_PW = os.getenv("POSTGRES_PW", "password")
|
|
POSTGRES_SERVER = os.getenv("POSTGRES_SERVER", "192.168.1.204")
|
|
POSTGRES_PORT = os.getenv("POSTGRES_PORT", "5432")
|
|
|
|
# Database name differs by environment
|
|
if CURRENT_SETTINGS == "PRODUCTION":
|
|
POSTGRES_DBNAME = os.getenv("POSTGRES_DBNAME", "auburnoil")
|
|
else:
|
|
POSTGRES_DBNAME = os.getenv("POSTGRES_DBNAME", "eamco")
|
|
|
|
# Build connection URI from components (fallback)
|
|
_DEFAULT_DATABASE_URI = "postgresql+psycopg2://{}:{}@{}:{}/{}".format(
|
|
POSTGRES_USERNAME,
|
|
POSTGRES_PW,
|
|
POSTGRES_SERVER,
|
|
POSTGRES_PORT,
|
|
POSTGRES_DBNAME
|
|
)
|
|
|
|
# Allow full DATABASE_URL override
|
|
DATABASE_URL: str = os.getenv("DATABASE_URL", _DEFAULT_DATABASE_URI)
|
|
|
|
# SQLAlchemy binds (for compatibility)
|
|
SQLALCHEMY_DATABASE_URI = DATABASE_URL
|
|
SQLALCHEMY_BINDS = {POSTGRES_DBNAME: SQLALCHEMY_DATABASE_URI}
|
|
|
|
# =============================================================================
|
|
# CORS CONFIGURATION
|
|
# =============================================================================
|
|
|
|
# Parse CORS origins from environment (comma-separated) or use defaults
|
|
_cors_env = os.getenv("CORS_ORIGINS", "")
|
|
|
|
if _cors_env:
|
|
CORS_ORIGINS: List[str] = [origin.strip() for origin in _cors_env.split(",")]
|
|
elif CURRENT_SETTINGS == "PRODUCTION":
|
|
# Production CORS origins
|
|
CORS_ORIGINS = [
|
|
"https://oil.edwineames.com",
|
|
"https://edwineames.com",
|
|
]
|
|
else:
|
|
# Development CORS origins
|
|
CORS_ORIGINS = [
|
|
"http://localhost:9000",
|
|
"https://localhost:9513",
|
|
"http://localhost:9514",
|
|
"http://localhost:9512",
|
|
"http://localhost:9511",
|
|
"http://localhost:5173", # Frontend port
|
|
"http://localhost:9616", # Authorize service port
|
|
]
|
|
|
|
# =============================================================================
|
|
# BATCH PROCESSING CONFIGURATION
|
|
# =============================================================================
|
|
|
|
# Maximum records to process in a single batch run
|
|
BATCH_SIZE: int = int(os.getenv("BATCH_SIZE", "150"))
|
|
|
|
# Records to process before committing to database
|
|
COMMIT_BATCH_SIZE: int = int(os.getenv("COMMIT_BATCH_SIZE", "20"))
|
|
|
|
# =============================================================================
|
|
# GEOCODING CONFIGURATION (Nominatim)
|
|
# =============================================================================
|
|
|
|
# User agent for Nominatim API (required - identifies your application)
|
|
NOMINATIM_USER_AGENT: str = "Unraid-EamcoAddressChecker/1.0 (eeames214@gmail.com)"
|
|
|
|
# Rate limiting: Sleep range between requests (Nominatim requires 1 req/sec max)
|
|
MIN_SLEEP_SECONDS: float = float(os.getenv("MIN_SLEEP", "1.2"))
|
|
MAX_SLEEP_SECONDS: float = float(os.getenv("MAX_SLEEP", "1.8"))
|
|
|
|
# Geocoding timeout in seconds
|
|
GEOCODE_TIMEOUT: int = int(os.getenv("GEOCODE_TIMEOUT", "10"))
|
|
|
|
# =============================================================================
|
|
# STATE MAPPING
|
|
# =============================================================================
|
|
|
|
# Integer -> US State Abbreviation mapping
|
|
# Replace with proper states table lookup when available
|
|
STATE_MAPPING: dict[int, str] = {
|
|
1: "AL", # Alabama
|
|
2: "AK", # Alaska
|
|
3: "AS", # American Samoa
|
|
4: "AZ", # Arizona
|
|
5: "AR", # Arkansas
|
|
6: "CA", # California
|
|
7: "CO", # Colorado
|
|
8: "CT", # Connecticut
|
|
9: "DE", # Delaware
|
|
10: "DC", # District of Columbia
|
|
11: "FL", # Florida
|
|
12: "GA", # Georgia
|
|
13: "GU", # Guam
|
|
14: "HI", # Hawaii
|
|
15: "ID", # Idaho
|
|
16: "IL", # Illinois
|
|
17: "IN", # Indiana
|
|
18: "IA", # Iowa
|
|
19: "KS", # Kansas
|
|
20: "KY", # Kentucky
|
|
21: "LA", # Louisiana
|
|
22: "ME", # Maine
|
|
23: "MD", # Maryland
|
|
24: "MA", # Massachusetts
|
|
25: "MI", # Michigan
|
|
26: "MN", # Minnesota
|
|
27: "MS", # Mississippi
|
|
28: "MO", # Missouri
|
|
29: "MT", # Montana
|
|
30: "NE", # Nebraska
|
|
31: "NV", # Nevada
|
|
32: "NH", # New Hampshire
|
|
33: "NJ", # New Jersey
|
|
34: "NM", # New Mexico
|
|
35: "NY", # New York
|
|
36: "NC", # North Carolina
|
|
37: "ND", # North Dakota
|
|
38: "OH", # Ohio
|
|
39: "OK", # Oklahoma
|
|
40: "OR", # Oregon
|
|
41: "PA", # Pennsylvania
|
|
42: "PR", # Puerto Rico
|
|
43: "RI", # Rhode Island
|
|
44: "SC", # South Carolina
|
|
45: "SD", # South Dakota
|
|
46: "TN", # Tennessee
|
|
47: "TX", # Texas
|
|
48: "UT", # Utah
|
|
49: "VT", # Vermont
|
|
50: "VA", # Virginia
|
|
51: "VI", # Virgin Islands
|
|
52: "WA", # Washington
|
|
53: "WV", # West Virginia
|
|
54: "WI", # Wisconsin
|
|
55: "WY", # Wyoming
|
|
}
|
|
|
|
# =============================================================================
|
|
# LOGGING CONFIGURATION
|
|
# =============================================================================
|
|
|
|
LOG_LEVEL: str = os.getenv("LOG_LEVEL", "INFO")
|
|
LOG_FORMAT: str = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
|