File size: 1,004 Bytes
7803d4e fb1fe87 7803d4e e4759e7 7803d4e d24d9cd 7803d4e fb1fe87 7803d4e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 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()
|