Add computed properties to settings

This commit is contained in:
Roman Krček
2024-10-13 21:05:51 +02:00
parent 47472d59b7
commit 47248f10ab
3 changed files with 17 additions and 5 deletions

View File

@@ -6,4 +6,5 @@ tiktok_downloader==0.3.5
uvloop==0.19.0
tgcrypto==1.2.5
sentry-sdk==2.15.0
pydantic-settings==2.5.2
pydantic-settings==2.5.2
pydantic==2.9.2

View File

@@ -3,9 +3,6 @@ from functools import wraps
from telegram_downloader_bot.logger import log
from telegram_downloader_bot.settings import settings
allowed_ids = settings.allowed_ids.split(",")
allowed_ids = [int(x) for x in allowed_ids]
def protected(func):
@wraps(func)

View File

@@ -1,5 +1,7 @@
import os
from functools import cached_property
from pydantic_settings import BaseSettings
from pydantic import computed_field
class Settings(BaseSettings):
@@ -46,10 +48,22 @@ class Settings(BaseSettings):
api_id: int
api_hash: str
bot_token: str
storage: os.path
storage: str
allowed_ids: str
log_level: str
@computed_field
@property
def tt_hash_file(self) -> str:
return os.path.join(settings.storage, "tt_hashes.pickle")
@computed_field
@cached_property
def allowed_ids_list(self) -> list:
allowed_ids = settings.allowed_ids.split(",")
allowed_ids = [int(x) for x in allowed_ids]
return allowed_ids
class Config:
env_file = ".env"