core to app again

This commit is contained in:
Dmitry Afanasyev 2022-08-16 14:45:44 +03:00
parent 94224f4401
commit d635ea768d
5 changed files with 19 additions and 15 deletions

View File

@ -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)

View File

@ -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:

View File

@ -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},

View File

@ -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

View File

@ -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
&& gunicorn app.main:create_app --bind prod-server.lan:8084 --worker-class aiohttp.GunicornWebWorker