diff --git a/Bot.py b/Bot.py index b18aaf5..b63a772 100755 --- a/Bot.py +++ b/Bot.py @@ -3,6 +3,12 @@ from loguru import logger from aiogram import Bot, Dispatcher, types from functions import get_audio_messages_func, create_statistic, openai_answer 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) # создаю объект слушателя @@ -23,13 +29,24 @@ async def start(message: types.Message): @dp.message_handler(commands=['statistic']) async def statistic(message: types.Message): - if message.chat.id != "": - for i in create_statistic.create_statistic(): - await bot.send_message(message.chat.id, i) - await bot.delete_message(message.chat.id, message.message_id) - else: - await bot.delete_message(message.chat.id, message.message_id) - await bot.send_message(message.chat.id, "У вас нет прав на просмотр статистики") + 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"]} уведомлений. Прочитайте хоть') @dp.message_handler(commands=['r'])