fixed env

pull/231/head
Yariv Menachem 2025-01-03 18:48:54 +02:00
parent f1fc22cb06
commit 90132ca199
1 changed files with 6 additions and 15 deletions

View File

@ -1,25 +1,16 @@
import os
from pydantic_settings import BaseSettings, SettingsConfigDict
from pydantic import Field
from pydantic_settings import BaseSettings
if not os.getenv("ENV"):
if not os.environ.get("ENV"):
raise ValueError("Invalid environment. Set the 'ENV' variable (e.g., export ENV=dev).")
dotenv_file = os.path.join(os.path.dirname(__file__), ".env." + os.environ.get("ENV"))
if not os.path.exists(dotenv_file):
raise FileNotFoundError(f"Environment file not found: {dotenv_file}")
class Settings(BaseSettings):
environment: str
telegram_api_token: str
mongo_uri: str
mongo_db_name: str
print(f"Loading environment from: {dotenv_file}")
model_config = SettingsConfigDict(
env_file=dotenv_file
)
telegram_api_token: str = Field(alias="telegram_api_token")
mongo_uri: str = Field(alias="mongo_uri")
mongo_db_name: str = Field(alias="mongo_db_name")
settings = Settings()