# AUTOGENERATED! DO NOT EDIT! File to edit: nbs/03-notificator.ipynb (unless otherwise specified).

__all__ = ['TelegramNotificator', 'send', 'TimewebBalanceNotificator', 'authorize']

# Cell

import telebot
import fastcore.basics as fcb
from .core import logger

# Cell

class TelegramNotificator:
    def __init__(self, token='6190703828:AAFksjz6MrtXDkQpTdiy7-A4zig0wT_g1Uo', chat_id='662822665'):

        # create attribute bot:
        self.bot = telebot.TeleBot(token)

        # create attribute chat_id:
        self.chat_id = chat_id

        logger.info(f"SUCCESS: started bot")

# Cell

@fcb.patch_to(TelegramNotificator)
def send(self, text):

    """
    METHOD TO SEND A TEXT MESSAGE.
    """
    bot = self.bot
    bot.send_message(self.chat_id, text)
    logger.info(f"SUCCESS: sent message")

# Cell
from .parser import Driver
from selenium import webdriver
from selenium.webdriver.common.by import By

from bs4 import BeautifulSoup
from time import sleep

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

# Cell
class TimewebBalanceNotificator:
    def __init__(self, login, password):

        # get attributes login and password:
        self.login = login
        self.password = password

        # get attribute driver:
        self.driver = Driver().get_driver()

# Cell

@fcb.patch_to(TimewebBalanceNotificator)
def authorize(self):

    """
    METHOD TO AUTHORIZE AT TIMEWEB.COM.
    """

    driver = self.driver
    login_url = 'https://hosting.timeweb.ru/login'
    driver.get(login_url)

    # wait the page to upload for up to 60 secs:
    WebDriverWait(driver, 60).until(EC.presence_of_element_located((By.XPATH, '//*[@id="login-page"]/div/div[1]/div/div/section/form/div[1]/input')))

    # input login and password:
    login_locator = driver.find_element(By.XPATH, '//*[@id="login-page"]/div/div[1]/div/div/section/form/div[1]/input')
    password_locator = driver.find_element(By.XPATH, '//*[@id="login-page"]/div/div[1]/div/div/section/form/div[2]/input')
    login_locator.send_keys(self.login)
    password_locator.send_keys(self.password)

    # click submit button:
    submit_button = driver.find_element(By.XPATH, '//*[@id="login-page"]/div/div[1]/div/div/section/form/div[4]/button')
    submit_button.click()
    sleep(2)