added week function

This commit is contained in:
2024-09-20 22:36:16 +09:00
parent b7d007ec79
commit 55d866eee4
2 changed files with 41 additions and 20 deletions

57
main.py
View File

@@ -5,6 +5,7 @@ from selenium.webdriver.common.by import By
import time
from bs4 import BeautifulSoup
import lxml
import threading
import discord
from discord.ext import commands
@@ -27,42 +28,58 @@ url = "https://amursu.ru/obrazovanie/timetable/timetable-group/?id_group=1891"
# 3. приводим в читаемый вид | fail
# 4. отправляем в дс | ок
def get_day_info(day : int, url : str) -> list:
'''Get's day of th week number
posible numbers: 3-9 (included)'''
def get_element_from_driver(url, instruction : list) -> list:
driver = webdriver.Firefox()
driver.implicitly_wait(10)
driver.get(url)
assert "Расписание" in driver.title
elem = []
arr = ''
elem.append(driver.find_element(By.XPATH, f'/html/body/main/div[2]/div/div/div[3]/div[4]/div[{day}]').get_attribute('innerHTML'))
for i in instruction:
elem.append(driver.find_element(By.XPATH, i).get_attribute('innerHTML'))
driver.close()
text = str(elem)
return elem
soup = BeautifulSoup(str(text), 'lxml')
def get_day_info(html : str) -> list:
'''Get's day of th week number
posible numbers: 3-9 (included)'''
soup = BeautifulSoup(html, 'lxml')
soupa = soup.findAll("a", attrs = {'class':'ui link blue speak'})
soup = BeautifulSoup(str(soupa)).find_all('a')
for data in soup:
arr += data.get('data-speech') + '\n'
print(arr)
return arr
soupa = ''
for data in soup:
soupa += data.get('data-speech') + '\n'
return soupa
def get_week_info():
week_info = []
for i in range(3, 10):
week_info.append(get_day_info())
return week_info
@prikols.command()
async def day(ctx, arg):
await ctx.send(get_day_info(arg, url=url))
try:
await ctx.send(get_day_info(arg, url=url))
except BaseException as err:
await ctx.send(err)
@prikols.command()
async def week(ctx, arg):
await ctx.send(get_day_info(arg, url=url))
async def week(ctx):
try:
arr = []
for day in range(3,9):
arr.append(f'/html/body/main/div[2]/div/div/div[3]/div[4]/div[{day}]')
html = get_element_from_driver(url=url, instruction=arr)
for i in html:
await ctx.send(get_day_info(i))
except BaseException as err:
await ctx.send(err)
# @prikols.command()
# async def week(ctx, arg):
# await ctx.send(get_day_info(arg, url=url))
@prikols.event
async def on_ready():