доделал работу с api yandex lyceum теперь без костылей

This commit is contained in:
2023-04-22 13:34:23 +07:00
parent 3176029cd2
commit 9aca8ad10e
5 changed files with 257 additions and 26 deletions
+7 -25
View File
@@ -1,14 +1,8 @@
from aiogram.utils import executor
from loguru import logger
from aiogram import Bot, Dispatcher, types
from functions import get_audio_messages_func, create_statistic, openai_answer
from functions import get_audio_messages_func, openai_answer, yandex
import json
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
import requests
import time
bot = Bot(token="5941118321:AAG0g0keLrlnuH_9U9X6ehpFFAdOX38qeXI") # создаю объект бота
dp = Dispatcher(bot) # создаю объект слушателя
@@ -29,24 +23,12 @@ async def start(message: types.Message):
@dp.message_handler(commands=['statistic'])
async def statistic(message: types.Message):
login = "Dmitrium12"
password = ""
options = webdriver.ChromeOptions()
options.add_argument("--headless")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
driver.get('https://passport.yandex.ru/auth/')
time.sleep(1)
driver.find_element(By.CLASS_NAME, "Button2").click()
time.sleep(1)
driver.find_element(By.XPATH, '//*[@id="passp-field-login"]').send_keys(login)
driver.find_element(By.XPATH, '//*[@id="passp:sign-in"]').click()
time.sleep(1)
driver.find_element(By.XPATH, '//*[@id="passp-field-passwd"]').send_keys(password)
driver.find_element(By.XPATH, '//*[@id="passp:sign-in"]').click()
time.sleep(5)
cookies = {"Session_id": [i["value"] for i in driver.get_cookies() if i["name"] == "Session_id"][0]}
response = requests.get("https://lyceum.yandex.ru/api/notifications?isRead=false&limit=20", cookies=cookies)
await message.reply(f'У вас {response.json()["unreadCount"]} уведомлений. Прочитайте хоть')
await yandex.statistic(message)
@dp.message_handler(commands=['create_yandex'])
async def create_yandex(message: types.Message):
await yandex.create_yandex(message)
@dp.message_handler(commands=['r'])