mirror of
https://github.com/Balshgit/mosgortrans.git
synced 2025-09-11 13:00:40 +03:00
add cron job
This commit is contained in:
parent
f4ded6ae10
commit
3ae46f8c0e
27
main.py
27
main.py
@ -1,8 +1,8 @@
|
||||
from aiogram import Bot, types
|
||||
from aiogram.contrib.middlewares.logging import LoggingMiddleware
|
||||
from aiogram.dispatcher import Dispatcher
|
||||
from aiogram.dispatcher.webhook import SendMessage, get_new_configured_app
|
||||
from aiogram.utils.executor import start_webhook, Executor
|
||||
from aiogram.dispatcher.webhook import SendMessage
|
||||
from aiogram.utils.executor import start_webhook
|
||||
|
||||
from mos_gor import logger, parse_site, download_gecko_driver, configure_firefox_driver
|
||||
from settings import API_TOKEN, WEBHOOK_URL, WEBHOOK_PATH, WEBAPP_HOST, WEBAPP_PORT
|
||||
@ -12,6 +12,15 @@ dp = Dispatcher(bot)
|
||||
dp.middleware.setup(LoggingMiddleware())
|
||||
|
||||
|
||||
@dp.message_handler(commands=['chatid'])
|
||||
async def echo(message: types.Message):
|
||||
# Regular request
|
||||
# await bot.send_message(message.chat.id, message.text)
|
||||
|
||||
# or reply INTO webhook
|
||||
return SendMessage(message.chat.id, message.chat.id)
|
||||
|
||||
|
||||
@dp.message_handler()
|
||||
async def echo(message: types.Message):
|
||||
# Regular request
|
||||
@ -23,6 +32,10 @@ async def echo(message: types.Message):
|
||||
return SendMessage(message.chat.id, text)
|
||||
|
||||
|
||||
async def send_message(chat_id: int, text: str):
|
||||
await bot.send_message(chat_id=chat_id, text=text, parse_mode=types.ParseMode.HTML)
|
||||
|
||||
|
||||
async def on_startup(dp):
|
||||
await bot.set_webhook(WEBHOOK_URL)
|
||||
# insert code here to run it after start
|
||||
@ -43,16 +56,6 @@ async def on_shutdown(dp):
|
||||
logger.warning('Bye!')
|
||||
|
||||
|
||||
async def async_app():
|
||||
app = get_new_configured_app(dispatcher=dp, path=WEBHOOK_PATH)
|
||||
executor = Executor(dp, skip_updates=True)
|
||||
executor.on_startup(on_startup)
|
||||
executor.on_shutdown(on_shutdown)
|
||||
executor._prepare_webhook(WEBHOOK_PATH, app=app)
|
||||
await executor._startup_webhook()
|
||||
return app
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
download_gecko_driver()
|
||||
driver = configure_firefox_driver()
|
||||
|
@ -68,4 +68,4 @@ def parse_site(driver: WebDriver) -> str:
|
||||
bus_t19_arrival = element.find_element(by='class name', value='masstransit-prognoses-view__title-text')
|
||||
except NoSuchElementException:
|
||||
pass
|
||||
return f'{bus_300.text} - {bus_300_arrival.text}\n{bus_t19.text} - {bus_t19_arrival.text}'
|
||||
return f'Автобус {bus_300.text} - {bus_300_arrival.text}\nАвтобус {bus_t19.text} - {bus_t19_arrival.text}'
|
||||
|
@ -1,6 +1,7 @@
|
||||
#! /bin/bash
|
||||
set -e
|
||||
|
||||
|
||||
echo "shutting down the bot"
|
||||
killall python;
|
||||
killall firefox;
|
||||
killall firefox
|
||||
killall python
|
Loading…
x
Reference in New Issue
Block a user