[dev] basic project structure
This commit is contained in:
2
src/utils/__init__.py
Normal file
2
src/utils/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from .env import env
|
||||
from .logging import logger
|
||||
0
src/utils/db/__init__.py
Normal file
0
src/utils/db/__init__.py
Normal file
9
src/utils/db/migrate.py
Normal file
9
src/utils/db/migrate.py
Normal file
@@ -0,0 +1,9 @@
|
||||
import asyncio
|
||||
from utils import env
|
||||
|
||||
|
||||
async def main():
|
||||
print(env.db.host)
|
||||
|
||||
|
||||
asyncio.run(main())
|
||||
0
src/utils/db/models/__init__.py
Normal file
0
src/utils/db/models/__init__.py
Normal file
41
src/utils/env.py
Normal file
41
src/utils/env.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from pydantic_settings import BaseSettings, SettingsConfigDict
|
||||
from pydantic import SecretStr
|
||||
|
||||
|
||||
class BotSettings(BaseSettings):
|
||||
token: SecretStr
|
||||
|
||||
|
||||
class DatabaseSettings(BaseSettings):
|
||||
host: str = "mongodb"
|
||||
port: int = 27017
|
||||
user: SecretStr = "user"
|
||||
password: SecretStr = "password"
|
||||
db_name: str = "prod"
|
||||
connection_params: str = ""
|
||||
|
||||
@property
|
||||
def connection_url(self) -> str:
|
||||
return f"mongodb://{self.user.get_secret_value()}:{self.password.get_secret_value()}@{self.host}:{self.port}/{self.db_name}{self.connection_params}"
|
||||
|
||||
|
||||
class LogSettings(BaseSettings):
|
||||
level: str = "INFO"
|
||||
show_time: bool = False
|
||||
console_width: int = 150
|
||||
|
||||
|
||||
class Settings(BaseSettings):
|
||||
bot: BotSettings
|
||||
db: DatabaseSettings
|
||||
log: LogSettings
|
||||
|
||||
model_config = SettingsConfigDict(
|
||||
case_sensitive=False,
|
||||
env_file=".env",
|
||||
env_nested_delimiter="__",
|
||||
extra="ignore",
|
||||
)
|
||||
|
||||
|
||||
env = Settings() # noqa
|
||||
38
src/utils/logging.py
Normal file
38
src/utils/logging.py
Normal file
@@ -0,0 +1,38 @@
|
||||
import logging
|
||||
|
||||
from rich.console import Console
|
||||
from rich.logging import RichHandler
|
||||
|
||||
from . import env
|
||||
|
||||
|
||||
console = Console(
|
||||
width=env.log.console_width,
|
||||
color_system="auto",
|
||||
force_terminal=True,
|
||||
)
|
||||
|
||||
|
||||
def setup_logging():
|
||||
from aiogram.dispatcher import router
|
||||
from dishka.integrations import aiogram
|
||||
|
||||
logging.basicConfig(
|
||||
level=env.log.level,
|
||||
format=None, # noqa
|
||||
datefmt=None,
|
||||
handlers=[
|
||||
RichHandler(
|
||||
console=console,
|
||||
markup=True,
|
||||
rich_tracebacks=True,
|
||||
tracebacks_show_locals=True,
|
||||
omit_repeated_times=False,
|
||||
show_time=env.log.show_time,
|
||||
tracebacks_suppress=[router, aiogram],
|
||||
)
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
Reference in New Issue
Block a user