init commit
This commit is contained in:
23
app/config.py
Normal file
23
app/config.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import os
|
||||
from dataclasses import dataclass
|
||||
|
||||
@dataclass
|
||||
class Config:
|
||||
bot_token: str
|
||||
database_url: str
|
||||
log_level: str = os.getenv("LOG_LEVEL", "INFO")
|
||||
|
||||
def load_config() -> "Config":
|
||||
bot_token = os.getenv("BOT_TOKEN", "").strip()
|
||||
if not bot_token:
|
||||
raise RuntimeError("BOT_TOKEN is not set")
|
||||
# DATABASE_URL takes precedence; else compose from parts
|
||||
db_url = os.getenv("DATABASE_URL", "").strip()
|
||||
if not db_url:
|
||||
host = os.getenv("DB_HOST", "db")
|
||||
port = os.getenv("DB_PORT", "5432")
|
||||
name = os.getenv("DB_NAME", "tg_poster")
|
||||
user = os.getenv("DB_USER", "postgres")
|
||||
pwd = os.getenv("DB_PASSWORD", "postgres")
|
||||
db_url = f"postgresql+psycopg://{user}:{pwd}@{host}:{port}/{name}"
|
||||
return Config(bot_token=bot_token, database_url=db_url)
|
||||
Reference in New Issue
Block a user