added dc bot
This commit is contained in:
72
main.py
72
main.py
@@ -1,14 +1,72 @@
|
|||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from selenium.webdriver.common.keys import Keys
|
from selenium.webdriver.firefox.options import Options
|
||||||
|
# from selenium.webdriver.common.keys import Keys
|
||||||
from selenium.webdriver.common.by import By
|
from selenium.webdriver.common.by import By
|
||||||
import time
|
import time
|
||||||
|
from bs4 import BeautifulSoup
|
||||||
|
import lxml
|
||||||
|
|
||||||
|
import discord
|
||||||
|
from discord.ext import commands
|
||||||
|
|
||||||
|
#objs
|
||||||
|
options = Options()
|
||||||
|
intents = discord.Intents.default()
|
||||||
|
prikols = commands.Bot(intents=intents, command_prefix = '!')
|
||||||
|
|
||||||
|
# consts
|
||||||
|
options.headless = True
|
||||||
|
intents.message_content = True
|
||||||
|
intents.messages = True
|
||||||
|
|
||||||
|
url = "https://amursu.ru/obrazovanie/timetable/timetable-group/?id_group=1891"
|
||||||
|
|
||||||
|
# гайд на завтра:
|
||||||
|
# 1. собираем все хпатх | ок
|
||||||
|
# 2. расчекрыживаем при помощи bs4 | ок
|
||||||
|
# 3. приводим в читаемый вид | fail
|
||||||
|
# 4. отправляем в дс | ок
|
||||||
|
|
||||||
|
def get_day_info(day : int, url : str) -> list:
|
||||||
|
'''Get's day of th week number
|
||||||
|
posible numbers: 3-9 (included)'''
|
||||||
driver = webdriver.Firefox()
|
driver = webdriver.Firefox()
|
||||||
driver.get("https://amursu.ru/obrazovanie/timetable/timetable-group/?id_group=1891")
|
driver.get(url)
|
||||||
assert "Расписание" in driver.title
|
assert "Расписание" in driver.title
|
||||||
# /html/body/main/div[2]/div/div/div[3]/div[4]/div[3]
|
|
||||||
infa = driver.find_element(By.XPATH, '/html/body/main/div[2]/div/div/div[3]/div[4]/div[7]/table/tbody/tr[1]/td[3]/div/div[2]')
|
elem = []
|
||||||
print(infa)
|
arr = ''
|
||||||
print(infa.text)
|
elem.append(driver.find_element(By.XPATH, f'/html/body/main/div[2]/div/div/div[3]/div[4]/div[{day}]').get_attribute('innerHTML'))
|
||||||
# time.sleep(10)
|
|
||||||
driver.close()
|
driver.close()
|
||||||
|
|
||||||
|
text = str(elem)
|
||||||
|
|
||||||
|
soup = BeautifulSoup(str(text), '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
|
||||||
|
|
||||||
|
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))
|
||||||
|
|
||||||
|
@prikols.command()
|
||||||
|
async def week(ctx, arg):
|
||||||
|
await ctx.send(get_day_info(arg, url=url))
|
||||||
|
|
||||||
|
@prikols.event
|
||||||
|
async def on_ready():
|
||||||
|
print('yolo')
|
||||||
|
|
||||||
|
# steal my token lol
|
||||||
|
prikols.run('MTE5ODIwMTEwMTU2OTI0OTM4MA.G7h2hW.ei4EZVmva7SymBijBO9tcx8xhNBtQMMSu4AsE0')
|
||||||
Reference in New Issue
Block a user