diff --git a/.gitignore b/.gitignore index 6bf70cf..386eea1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -.env *.sqlite -config.py +config.ini diff --git a/Dockerfile b/Dockerfile index 5ac33ba..b871d25 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,6 +2,7 @@ FROM python:3.10-slim-bullseye WORKDIR /app +COPY config.ini config.ini COPY requirements.txt requirements.txt ENV PATH=/venv/bin:$PATH @@ -10,6 +11,6 @@ RUN :\ && pip install --no-cache-dir pip -U wheel setuptools -r requirements.txt \ && : -COPY ./bot . +COPY ./bot ./bot -CMD ["python", "main.py"] +CMD ["python", "bot/main.py"] diff --git a/bot/config.py b/bot/config.py new file mode 100644 index 0000000..0dbd5cc --- /dev/null +++ b/bot/config.py @@ -0,0 +1,37 @@ +import configparser +from dataclasses import dataclass +from pathlib import Path + +import pytz + +_CONFIG_INI_PATH = Path(__file__).absolute().parent.parent / 'config.ini' +_default_token = '22:aa-F-6eNoKY65R-omFA' +_admin_id = 123 + +configreader = configparser.ConfigParser() +if not _CONFIG_INI_PATH.exists(): + token = _default_token + admin = _admin_id +else: + configreader.read(_CONFIG_INI_PATH) + try: + admin = int(configreader['config']['admin']) + token = configreader['config']['token'] + except (KeyError, ValueError): + print(f"You didn't setup your {_CONFIG_INI_PATH}. See example.config.ini") + raise SystemExit(1) + + +@dataclass +class Config: + token: str = token + admin: int = admin + conn_str: str = 'sqlite:///./db/budget.sqlite' + migration_script_location: Path = Path(__file__).parent / 'migrations' + alembic_config_path: Path = Path(__file__).parent / 'alembic.ini' + tz = pytz.timezone('Asia/Yerevan') + last: int = 10 + replenishment_name: str = '_replenishemnt' + + +config = Config() diff --git a/bot/config.py.example b/bot/config.py.example deleted file mode 100644 index fe63244..0000000 --- a/bot/config.py.example +++ /dev/null @@ -1,19 +0,0 @@ -import pytz - -from pathlib import Path -from dataclasses import dataclass - - -@dataclass -class Config: - token: str = '22:aa-F-6eNoKY65R-omFA' - admin: int = 1245 - conn_str: str ='sqlite:///./db/budget.sqlite' - migration_script_location: Path = Path(__file__).parent / 'migrations' - alembic_config_path: Path = Path(__file__).parent / 'alembic.ini' - tz = pytz.timezone('Asia/Yerevan') - last: int = 10 - replenishment_name: str = '_replenishemnt' - - -config = Config() diff --git a/example.config.ini b/example.config.ini new file mode 100644 index 0000000..62f2cb6 --- /dev/null +++ b/example.config.ini @@ -0,0 +1,3 @@ +[config] +admin = 123 +token = 01:AJCDoV-F-6e5R-oA