GithubHelp home page GithubHelp logo

onlinetaskbot's Introduction

OnlineTaskBot

onlinetaskbot's People

Contributors

whitehodok avatar

Watchers

 avatar

onlinetaskbot's Issues

Parser on Selenium

import datetime
from selenium import webdriver

Определяем сегодняшнюю дату в формате, используемом на сайте

today = datetime.date.today()
today_str = today.strftime("%d.%m.%Y")

Задаем URL сайта и группу

url = f"https://rasp.omgtu.ru/?t={today_str}"
group = 'АТП-221'

Открываем браузер и заходим на сайт

options = webdriver.ChromeOptions()
options.add_argument('headless')
browser = webdriver.Chrome(options=options)
browser.get(url)

Находим поле ввода для группы и вводим нашу группу

input_field = browser.find_element_by_id('group')
input_field.send_keys(group)

Находим кнопку "Найти" и кликаем на нее

button = browser.find_element_by_xpath('//button[text()="Найти"]')
button.click()

Находим таблицу с расписанием и выводим ее содержимое

table = browser.find_element_by_xpath('//table[@Class="table table-bordered table-striped table-hover"]')
print(table.text)

Закрываем браузер

browser.quit()

botv1

import asyncio
import datetime
import pytz
from aiogram import Bot, Dispatcher, types
from aiogram.utils import executor
from bs4 import BeautifulSoup
import os
from dotenv import load_dotenv
from selenium import webdriver

'''
Этот бот предназначен для отслеживания изменений в расписании группы АТП-221
Глубина поиска: 2 недели
Время обновления: 1 раз в 6 часов, с последующим уведомлением, если расписание изменилось
'''

def get_schedule():
url = 'https://rasp.omgtu.ru/group/show/11138'
driver = webdriver.Firefox()
driver.get(url)
soup = BeautifulSoup(driver.page_source, 'html.parser')
schedule_table = soup.find('div', {'class': 'media day ng-star-inserted'})
schedule = []
if schedule_table is None:
raise ValueError("Unable to locate schedule table on webpage")
for row in schedule_table.find_all('tr')[1:]:
columns = row.find_all('td')
schedule.append({
'time': columns[0].text.strip(),
'subject': columns[1].text.strip(),
'type': columns[2].text.strip(),
'teacher': columns[3].text.strip(),
'room': columns[4].text.strip(),
})
driver.close()
return schedule

bot_token = ''
bot = Bot(token=bot_token)
dispatcher = Dispatcher(bot)

async def send_notification(chat_id, message):
await bot.send_message(chat_id, message)

async def check_schedule():
old_schedule = []
while True:
schedule = get_schedule()
if schedule != old_schedule:
message = 'Расписание на {} изменилось:\n\n'.format(datetime.date.today())
for item in schedule:
message += '{} {} {}\n{} {}\n\n'.format(item['time'], item['subject'], item['type'], item['teacher'], item['room'])
await send_notification(chat_id, message)
old_schedule = schedule
await asyncio.sleep(60 * 60 * 6)

if name == 'main':
chat_id = '415378656'
loop = asyncio.get_event_loop()
loop.create_task(check_schedule())
executor.start_polling(dispatcher, loop=loop, skip_updates=True)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.