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