added .env.local support
This commit is contained in:
commit
25632e1938
10 files changed
+831
No files matched your search
@@ -0,0 +1,49 @@
|
||||
import json
|
||||
from enum import Enum
|
||||
from functools import cache
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
|
||||
from monitor_utils.constants import PROXIES_PATH, PROJECT_ROOT
|
||||
|
||||
|
||||
class DevelopmentMode(str, Enum):
|
||||
PRODUCTION = "PRODUCTION"
|
||||
DEVELOPMENT = "DEVELOPMENT"
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
mongo_url: str
|
||||
mongo_database_name: str
|
||||
production_bot_token: str
|
||||
profit_api_key: str
|
||||
development_bot_token: str | None = None
|
||||
logging_level: str = "INFO"
|
||||
development_mode: DevelopmentMode = DevelopmentMode.PRODUCTION
|
||||
|
||||
model_config = SettingsConfigDict(env_file=(".env", ".env.local"), extra="ignore")
|
||||
|
||||
|
||||
@cache
|
||||
def get_settings() -> Settings:
|
||||
return Settings()
|
||||
|
||||
|
||||
@cache
|
||||
def get_proxies() -> list[str]:
|
||||
with PROXIES_PATH.open() as f:
|
||||
proxies = [f"http://{p.strip()}" for p in f if p.strip()]
|
||||
|
||||
if not proxies:
|
||||
raise ValueError("Proxy list cannot be empty")
|
||||
|
||||
return proxies
|
||||
|
||||
|
||||
def get_config(config_name: str, use_production_path: bool = False) -> dict:
|
||||
config_name = config_name.replace(".json", "")
|
||||
if use_production_path:
|
||||
config_path = PROJECT_ROOT / "configs" / f"{config_name}.json"
|
||||
else:
|
||||
config_path = PROJECT_ROOT / "tests" / "configs" / f"{config_name}.json"
|
||||
with open(config_path) as config:
|
||||
return json.load(config)
|
||||
Reference in new issue
Block a user