First commit

This commit is contained in:
Alexey Sokolov
2022-02-09 16:49:52 +03:00
commit 74dec8960b
3 changed files with 439 additions and 0 deletions

33
config.py Normal file
View File

@@ -0,0 +1,33 @@
from os import getenv
from dataclasses import dataclass
@dataclass
class Config:
api_token: str
bot_owner: int
class ConfigError(Exception):
pass
_api_token = getenv('LTLNOTIFIER_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')
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')
config = Config(api_token=_api_token, bot_owner=_bot_owner)
__all__ = ['Config', config]