From 784cae145d1d82d890ef7791402811d88419d914 Mon Sep 17 00:00:00 2001 From: Crystal Melting Dot Date: Sun, 21 Feb 2021 13:14:55 +0300 Subject: [PATCH] better structure --- apps/Dockerfile-tgbot | 2 +- apps/tgbot/pyproject.toml | 3 +++ apps/tgbot/{ => tgbot}/bot.py | 13 +++++++++---- 3 files changed, 13 insertions(+), 5 deletions(-) rename apps/tgbot/{ => tgbot}/bot.py (89%) diff --git a/apps/Dockerfile-tgbot b/apps/Dockerfile-tgbot index 61dce7b..8bd8efc 100644 --- a/apps/Dockerfile-tgbot +++ b/apps/Dockerfile-tgbot @@ -10,4 +10,4 @@ RUN apk update \ COPY . . WORKDIR tgbot RUN pip install --upgrade pip; pip install poetry; poetry config virtualenvs.create false; poetry install -CMD poetry shell; python bot.py +CMD poetry run tgbot diff --git a/apps/tgbot/pyproject.toml b/apps/tgbot/pyproject.toml index fd54c57..97db224 100644 --- a/apps/tgbot/pyproject.toml +++ b/apps/tgbot/pyproject.toml @@ -23,3 +23,6 @@ flake8 = "^3.8.4" [build-system] requires = ["poetry-core>=1.0.0"] build-backend = "poetry.core.masonry.api" + +[tool.poetry.scripts] +tgbot = "tgbot.bot:main" \ No newline at end of file diff --git a/apps/tgbot/bot.py b/apps/tgbot/tgbot/bot.py similarity index 89% rename from apps/tgbot/bot.py rename to apps/tgbot/tgbot/bot.py index 38d73c6..bf2a7fc 100644 --- a/apps/tgbot/bot.py +++ b/apps/tgbot/tgbot/bot.py @@ -1,12 +1,12 @@ from aiogram import Bot, Dispatcher, executor from aiogram.contrib.fsm_storage.memory import MemoryStorage -from tgbot.middlewares import UserMiddleware, WriteCommandMetric, LoggingMiddleware, ThrottlingMiddleware +from .middlewares import UserMiddleware, WriteCommandMetric, LoggingMiddleware, ThrottlingMiddleware from tortoise import Tortoise from tortoise.exceptions import DBConnectionError from loguru import logger from asyncio import sleep -import tgbot.config as config -import tgbot.handlers as handlers +from . import config +from . import handlers storage = MemoryStorage() telegram_bot = Bot(token=config.TELEGRAM_BOT_TOKEN) @@ -42,5 +42,10 @@ async def on_startup(disp: Dispatcher): disp.middleware.setup(LoggingMiddleware()) disp.middleware.setup(UserMiddleware()) -if __name__ == '__main__': + +def main(): executor.start_polling(dp, skip_updates=True, on_startup=on_startup) + + +if __name__ == '__main__': + main()