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 import Dispatcher
from aiogram.dispatcher.webhook import SendMessage from aiogram.dispatcher.webhook import SendMessage
from aiogram.utils.callback_data import CallbackData from aiogram.utils.callback_data import CallbackData
from core.parse_web import configure_firefox_driver, download_gecko_driver, parse_site from app.core.parse_web import (
from settings import API_TOKEN configure_firefox_driver,
download_gecko_driver,
parse_site,
)
from app.settings import API_TOKEN
bot = Bot(token=API_TOKEN) bot = Bot(token=API_TOKEN)
dispatcher = Dispatcher(bot) dispatcher = Dispatcher(bot)

View File

@ -4,13 +4,13 @@ import time
from pathlib import Path from pathlib import Path
import wget 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 import webdriver
from selenium.common.exceptions import NoSuchElementException, WebDriverException from selenium.common.exceptions import NoSuchElementException, WebDriverException
from selenium.webdriver.firefox import options from selenium.webdriver.firefox import options
from selenium.webdriver.firefox.service import Service from selenium.webdriver.firefox.service import Service
from selenium.webdriver.firefox.webdriver import WebDriver from selenium.webdriver.firefox.webdriver import WebDriver
from settings import BASE_DIR, GECKO_DRIVER_VERSION
def download_gecko_driver() -> None: 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 = [ cron_jobs = [
{'trigger': 'cron', 'day_of_week': 'mon-fri', 'hour': 8, 'minute': 59, 'second': 0}, {'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.types import Update
from aiogram.utils.executor import start_polling, start_webhook from aiogram.utils.executor import start_polling, start_webhook
from aiohttp import web from aiohttp import web
from core.bot import bot, dispatcher from app.core.bot import bot, dispatcher
from core.logger import logger from app.core.logger import logger
from core.scheduler import asyncio_schedule from app.core.scheduler import asyncio_schedule
from settings import ( from app.settings import (
START_WITH_WEBHOOK, START_WITH_WEBHOOK,
WEBAPP_HOST, WEBAPP_HOST,
WEBAPP_PORT, WEBAPP_PORT,
@ -59,10 +59,10 @@ def bot_webhook() -> None:
async def webhook(request: web.Request) -> web.Response: async def webhook(request: web.Request) -> web.Response:
data = await request.json() data = await request.json()
logger.info(data)
Bot.set_current(dispatcher.bot)
Dispatcher.set_current(dispatcher)
tg_update = Update(**data) tg_update = Update(**data)
logger.info(data)
Dispatcher.set_current(dispatcher)
Bot.set_current(dispatcher.bot)
await dispatcher.process_update(tg_update) await dispatcher.process_update(tg_update)
return web.Response(status=HTTPStatus.OK) 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: async def create_app() -> web.Application:
application = 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) application.on_startup.append(on_startup_gunicorn)
return application return application

View File

@ -2,6 +2,6 @@
echo "starting the bot" echo "starting the bot"
cd /opt/mosgortrans/app \ cd /opt/mosgortrans \
&& source /home/balsh/.cache/pypoetry/virtualenvs/mosgortrans-3eZxMcY3-py3.10/bin/activate \ && 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