diff --git a/app/core/bot.py b/app/core/bot.py index c82bc88..6f54369 100644 --- a/app/core/bot.py +++ b/app/core/bot.py @@ -5,8 +5,12 @@ from aiogram.contrib.middlewares.logging import LoggingMiddleware from aiogram.dispatcher import Dispatcher from aiogram.dispatcher.webhook import SendMessage from aiogram.utils.callback_data import CallbackData -from core.parse_web import configure_firefox_driver, download_gecko_driver, parse_site -from settings import API_TOKEN +from app.core.parse_web import ( + configure_firefox_driver, + download_gecko_driver, + parse_site, +) +from app.settings import API_TOKEN bot = Bot(token=API_TOKEN) dispatcher = Dispatcher(bot) diff --git a/app/core/parse_web.py b/app/core/parse_web.py index 7c4e304..49ff684 100644 --- a/app/core/parse_web.py +++ b/app/core/parse_web.py @@ -4,13 +4,13 @@ import time from pathlib import Path import wget -from core.logger import logger +from app.core.logger import logger +from app.settings import BASE_DIR, GECKO_DRIVER_VERSION from selenium import webdriver from selenium.common.exceptions import NoSuchElementException, WebDriverException from selenium.webdriver.firefox import options from selenium.webdriver.firefox.service import Service from selenium.webdriver.firefox.webdriver import WebDriver -from settings import BASE_DIR, GECKO_DRIVER_VERSION def download_gecko_driver() -> None: diff --git a/app/core/scheduler.py b/app/core/scheduler.py index c53deb6..de5ccd2 100644 --- a/app/core/scheduler.py +++ b/app/core/scheduler.py @@ -1,4 +1,4 @@ -from core.bot import morning_bus_mailing +from app.core.bot import morning_bus_mailing cron_jobs = [ {'trigger': 'cron', 'day_of_week': 'mon-fri', 'hour': 8, 'minute': 59, 'second': 0}, diff --git a/app/main.py b/app/main.py index b56cbe8..bb1155f 100644 --- a/app/main.py +++ b/app/main.py @@ -4,10 +4,10 @@ from aiogram import Bot, Dispatcher from aiogram.types import Update from aiogram.utils.executor import start_polling, start_webhook from aiohttp import web -from core.bot import bot, dispatcher -from core.logger import logger -from core.scheduler import asyncio_schedule -from settings import ( +from app.core.bot import bot, dispatcher +from app.core.logger import logger +from app.core.scheduler import asyncio_schedule +from app.settings import ( START_WITH_WEBHOOK, WEBAPP_HOST, WEBAPP_PORT, @@ -59,10 +59,10 @@ def bot_webhook() -> None: async def webhook(request: web.Request) -> web.Response: data = await request.json() - logger.info(data) - Bot.set_current(dispatcher.bot) - Dispatcher.set_current(dispatcher) tg_update = Update(**data) + logger.info(data) + Dispatcher.set_current(dispatcher) + Bot.set_current(dispatcher.bot) await dispatcher.process_update(tg_update) return web.Response(status=HTTPStatus.OK) @@ -74,7 +74,7 @@ async def on_startup_gunicorn(app: web.Application) -> None: async def create_app() -> web.Application: application = web.Application() - application.router.add_post('/transport', webhook) + application.router.add_post(WEBHOOK_PATH, webhook) application.on_startup.append(on_startup_gunicorn) return application diff --git a/scripts/start-bot.sh b/scripts/start-bot.sh index 4f3a757..80bd6b2 100644 --- a/scripts/start-bot.sh +++ b/scripts/start-bot.sh @@ -2,6 +2,6 @@ echo "starting the bot" -cd /opt/mosgortrans/app \ +cd /opt/mosgortrans \ && source /home/balsh/.cache/pypoetry/virtualenvs/mosgortrans-3eZxMcY3-py3.10/bin/activate \ -&& gunicorn main:create_app --bind prod-server.lan:8084 --worker-class aiohttp.GunicornWebWorker \ No newline at end of file +&& gunicorn app.main:create_app --bind prod-server.lan:8084 --worker-class aiohttp.GunicornWebWorker \ No newline at end of file