51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
from os import getenv
|
|
from dataclasses import dataclass
|
|
|
|
|
|
@dataclass
|
|
class Config:
|
|
"""
|
|
Notifier config dataclass.
|
|
|
|
* `base_url`: url of domain
|
|
* `teletoken`: telegram api token.
|
|
* `param bot_owner`: telegram id of bot owner.
|
|
"""
|
|
base_url: str
|
|
teletoken: str
|
|
bot_owner: int
|
|
|
|
|
|
class ConfigError(Exception):
|
|
pass
|
|
|
|
|
|
_teletoken = getenv('LTLNOTIFIER_TELETOKEN')
|
|
print(_teletoken[9])
|
|
# Check api token
|
|
if not _teletoken:
|
|
raise ConfigError('virtual environment LTLNOTIFIER_TELETOKEN not set.')
|
|
if len(_teletoken) != 45 or _teletoken[9] != ':' or not _teletoken[:9].isdigit():
|
|
raise ConfigError('virtual environment LTLNOTIFIER_TELETOKEN 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(teletoken=_teletoken, bot_owner=_bot_owner, base_url=_base_url)
|
|
|
|
__all__ = ['Config', 'config']
|