mirror of
https://github.com/Balshgit/mosgortrans.git
synced 2025-09-11 13:00:40 +03:00
80 lines
2.8 KiB
Python
80 lines
2.8 KiB
Python
import asyncio
|
|
|
|
from aiogram import Bot, types
|
|
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 parse_site, configure_firefox_driver
|
|
from settings import API_TOKEN
|
|
|
|
bot = Bot(token=API_TOKEN)
|
|
dispatcher = Dispatcher(bot)
|
|
dispatcher.middleware.setup(LoggingMiddleware())
|
|
|
|
driver = configure_firefox_driver()
|
|
|
|
stations_cb = CallbackData('station', 'direction')
|
|
|
|
|
|
def get_keyboard() -> types.InlineKeyboardMarkup:
|
|
"""
|
|
Generate keyboard with list of posts
|
|
"""
|
|
markup = types.InlineKeyboardMarkup()
|
|
|
|
markup.row(
|
|
types.InlineKeyboardButton('Дом -> Офис', callback_data=stations_cb.new(direction='home->office')),
|
|
types.InlineKeyboardButton('Офис -> Дом', callback_data=stations_cb.new(direction='office->home')),
|
|
)
|
|
return markup
|
|
|
|
|
|
@dispatcher.callback_query_handler(stations_cb.filter(direction='home->office'))
|
|
async def home_office(query: types.CallbackQuery, callback_data: dict[str, str]) -> SendMessage:
|
|
|
|
text = parse_site(
|
|
driver=driver,
|
|
url='https://yandex.ru/maps/213/moscow/stops/stop__9640740/'
|
|
'?l=masstransit&ll=37.527754%2C55.823507&tab=overview&z=21',
|
|
message='Остановка Б. Академическая ул, д. 15'
|
|
)
|
|
|
|
return SendMessage(query.message.chat.id, text, reply_markup=get_keyboard())
|
|
|
|
|
|
@dispatcher.callback_query_handler(stations_cb.filter(direction='office->home'))
|
|
async def office_home(query: types.CallbackQuery, callback_data: dict[str, str]) -> SendMessage:
|
|
|
|
text = parse_site(
|
|
driver=driver,
|
|
url='https://yandex.ru/maps/213/moscow/stops/stop__9640288/?'
|
|
'l=masstransit&ll=37.505338%2C55.800160&tab=overview&z=211',
|
|
message='Остановка Улица Алабяна'
|
|
)
|
|
return SendMessage(query.message.chat.id, text, reply_markup=get_keyboard())
|
|
|
|
|
|
@dispatcher.message_handler(commands=['chatid'])
|
|
async def chat_id(message: types.Message) -> SendMessage:
|
|
|
|
return SendMessage(message.chat.id, message.chat.id)
|
|
|
|
|
|
@dispatcher.message_handler()
|
|
async def echo(message: types.Message) -> SendMessage:
|
|
return SendMessage(message.chat.id, 'Выбери остановку', reply_markup=get_keyboard())
|
|
|
|
|
|
async def send_message(chat_ids: list[int]) -> None:
|
|
text = parse_site(
|
|
driver=driver,
|
|
url='https://yandex.ru/maps/213/moscow/stops/stop__9640740/'
|
|
'?l=masstransit&ll=37.527754%2C55.823507&tab=overview&z=21',
|
|
message='Остановка Б. Академическая ул, д. 15'
|
|
)
|
|
await asyncio.gather(
|
|
*[bot.send_message(chat_id=chat_id, text=text, parse_mode=types.ParseMode.HTML) for chat_id in chat_ids]
|
|
)
|