added docstrings in config.py
This commit is contained in:
16
config.py
16
config.py
@@ -4,6 +4,12 @@ from dataclasses import dataclass
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Config:
|
class Config:
|
||||||
|
"""
|
||||||
|
Notifier config dataclass.
|
||||||
|
|
||||||
|
* `api_token`: telegram api token.
|
||||||
|
* `param bot_owner`: telegram id of bot owner.
|
||||||
|
"""
|
||||||
api_token: str
|
api_token: str
|
||||||
bot_owner: int
|
bot_owner: int
|
||||||
|
|
||||||
@@ -13,21 +19,23 @@ class ConfigError(Exception):
|
|||||||
|
|
||||||
|
|
||||||
_api_token = getenv('LTLNOTIFIER_API_TOKEN')
|
_api_token = getenv('LTLNOTIFIER_API_TOKEN')
|
||||||
|
# Check api token
|
||||||
if not _api_token:
|
if not _api_token:
|
||||||
raise ConfigError('virtual environment LTLNOTIFIER_API_TOKEN not set.')
|
raise ConfigError('virtual environment LTLNOTIFIER_API_TOKEN not set.')
|
||||||
if len(_api_token) != 45 or _api_token[9] or not _api_token[:9].isdigit():
|
if len(_api_token) != 45 or _api_token[9] or not _api_token[:9].isdigit():
|
||||||
raise ConfigError('Virtual environment LTLNOTIFIER_API_TOKEN incorrect')
|
raise ConfigError('virtual environment LTLNOTIFIER_API_TOKEN incorrect.')
|
||||||
|
|
||||||
_bot_owner = getenv('LTLNOTIFIER_BOT_OWNER')
|
_bot_owner = getenv('LTLNOTIFIER_BOT_OWNER')
|
||||||
|
# Check bot owner
|
||||||
if not _bot_owner:
|
if not _bot_owner:
|
||||||
raise ConfigError('Virtual environment LTLNOTIFIER_BOT_OWNER not set')
|
raise ConfigError('virtual environment LTLNOTIFIER_BOT_OWNER not set.')
|
||||||
try:
|
try:
|
||||||
if len(_bot_owner) != 9:
|
if len(_bot_owner) != 9:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
_bot_owner = int(_bot_owner)
|
_bot_owner = int(_bot_owner)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
raise ConfigError('Virtual environment LTLNOTIFIER_BOT_OWNER incorrect')
|
raise ConfigError('virtual environment LTLNOTIFIER_BOT_OWNER incorrect.')
|
||||||
|
|
||||||
config = Config(api_token=_api_token, bot_owner=_bot_owner)
|
config = Config(api_token=_api_token, bot_owner=_bot_owner)
|
||||||
|
|
||||||
__all__ = ['Config', config]
|
__all__ = ['Config', 'config']
|
||||||
|
|||||||
Reference in New Issue
Block a user