FlyRates / core /config.py
Sadeep Sachintha
feat: add production webhook safeguard for local development
d24d9cd
from pydantic_settings import BaseSettings, SettingsConfigDict
from pydantic import field_validator
from typing import Optional
class Settings(BaseSettings):
bot_token: str = ""
webhook_url: Optional[str] = None
telegram_api_server: Optional[str] = None
fx_api_key: str = ""
database_url: str = "sqlite+aiosqlite:///./flyrates.db"
log_level: str = "INFO"
delete_webhook_on_local: bool = False
@field_validator("database_url", mode="before")
@classmethod
def assemble_db_connection(cls, v: str) -> str:
if isinstance(v, str):
if v.startswith("postgres://"):
return v.replace("postgres://", "postgresql+asyncpg://", 1)
if v.startswith("postgresql://") and not v.startswith("postgresql+asyncpg://"):
return v.replace("postgresql://", "postgresql+asyncpg://", 1)
return v
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8", extra="ignore")
settings = Settings()