from os import getenv from dataclasses import dataclass @dataclass class Config: """ Notifier config dataclass. * `base_url`: url of domain * `api_token`: telegram api token. * `param bot_owner`: telegram id of bot owner. """ base_url: str api_token: str bot_owner: int class ConfigError(Exception): pass _api_token = getenv('LTLNOTIFIER_API_TOKEN') print(_api_token[9]) # Check api token if not _api_token: raise ConfigError('virtual environment LTLNOTIFIER_API_TOKEN not set.') if len(_api_token) != 45 or _api_token[9] != ':' or not _api_token[:9].isdigit(): raise ConfigError('virtual environment LTLNOTIFIER_API_TOKEN incorrect.') _bot_owner = getenv('LTLNOTIFIER_BOT_OWNER') print(_bot_owner) # Check bot owner if not _bot_owner: raise ConfigError('virtual environment LTLNOTIFIER_BOT_OWNER not set.') try: if len(_bot_owner) != 9: raise ValueError _bot_owner = int(_bot_owner) except ValueError: raise ConfigError('virtual environment LTLNOTIFIER_BOT_OWNER incorrect.') _base_url = getenv('LTLNOTIFIER_BASE_URL') # Check base url if not _base_url: raise ConfigError('virtual environment LTLNOTIFIER_BASE_URL not set') config = Config(api_token=_api_token, bot_owner=_bot_owner, base_url=_base_url) __all__ = ['Config', 'config']