mirror of
https://github.com/Balshgit/mosgortrans.git
synced 2026-02-03 11:20:56 +03:00
reduce web_parser time to 1 sec
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import asyncio
|
||||
from concurrent.futures.thread import ThreadPoolExecutor
|
||||
|
||||
from aiogram import Bot, types
|
||||
from aiogram.contrib.middlewares.logging import LoggingMiddleware
|
||||
@@ -22,8 +21,6 @@ driver = configure_firefox_driver()
|
||||
|
||||
stations_cb = CallbackData('station', 'direction')
|
||||
|
||||
executor = ThreadPoolExecutor(10)
|
||||
|
||||
|
||||
def get_keyboard() -> types.InlineKeyboardMarkup:
|
||||
"""
|
||||
|
||||
@@ -52,7 +52,7 @@ def parse_site(url: str, message: str, driver: WebDriver | None = None) -> str:
|
||||
logger.error('Driver is not configured')
|
||||
return 'Что-то пошло не так. :( Драйвер Firefox не сконфигурирован.'
|
||||
driver.get(url)
|
||||
time.sleep(4)
|
||||
time.sleep(1)
|
||||
elements = driver.find_elements(
|
||||
by='class name', value='masstransit-vehicle-snippet-view'
|
||||
)
|
||||
|
||||
13
app/main.py
13
app/main.py
@@ -1,9 +1,15 @@
|
||||
import asyncio
|
||||
import sys
|
||||
from http import HTTPStatus
|
||||
from pathlib import Path
|
||||
|
||||
from aiogram import Bot, Dispatcher
|
||||
from aiogram.types import Update
|
||||
from aiogram.utils.executor import start_polling
|
||||
from aiohttp import web
|
||||
|
||||
sys.path.append(str(Path(__file__).parent.parent))
|
||||
|
||||
from app.core.bot import bot, dispatcher
|
||||
from app.core.logger import logger
|
||||
from app.core.scheduler import asyncio_schedule
|
||||
@@ -19,7 +25,7 @@ from app.settings import (
|
||||
|
||||
async def bot_startup() -> None:
|
||||
await bot.set_webhook(WEBHOOK_URL)
|
||||
logger.info(f'Webhook set to {WEBHOOK_URL}')
|
||||
logger.info(f'Webhook set to {WEBHOOK_URL}'.replace(API_TOKEN, '{BOT_API_TOKEN}'))
|
||||
asyncio_schedule()
|
||||
|
||||
|
||||
@@ -33,6 +39,11 @@ async def bot_shutdown() -> None:
|
||||
await dispatcher.storage.close()
|
||||
await dispatcher.storage.wait_closed()
|
||||
|
||||
session = await bot.get_session()
|
||||
if session and not session.closed:
|
||||
await session.close()
|
||||
await asyncio.sleep(0.2)
|
||||
|
||||
logger.warning('Bye!')
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user