import os, tqdm, sys
import requests
import urllib.request
import re
#from bs4 import BeautifulSoup
import multiprocessing
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options

#from webdriver_manager.firefox import GeckoDriverManager
from selenium import webdriver
from utillc import *
from selenium.webdriver.firefox.service import Service as ServiceF
from selenium.webdriver.chrome.service import Service as ServiceC
import PIL
from selenium import webdriver
from selenium.webdriver.common.keys import Keys

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.common.exceptions import TimeoutException
import numpy as np
#wd = browser = webdriver.Firefox(executable_path=    GeckoDriverManager().install())
EKO()
import sys
from selenium.webdriver.firefox.options import Options as FirefoxOptions
from selenium.webdriver.chrome.options import Options as ChromeOptions
import time
import cherrypy
import argparse
import PIL
from PIL import Image
import orange

def tqdmtqdm(x) : return x

class P(orange.RobotBase) :

    def __init__(self) :
        super().__init__()
        self.build(headless=False)
        pass

    def xx() :
        options = FirefoxOptions()
        options = ChromeOptions()
        options.add_argument('--headless')
        options.add_argument('--no-sandbox')
        options.add_argument('--disable-dev-shm-usage')
        # changing user-agent because etoro detects the automated browser somehow
        options.add_argument("user-agent=Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) "
                             "Chrome/86.0.4240.183 Safari/537.36")
        EKO()


        s = ServiceC('/usr/bin/chromedriver')
        bot = self.driver = webdriver.Chrome(service=s, options=options)
        #self.driver = webdriver.Chrome('/usr/lib/chromium-browser/chromedriver', options=options)
        #self.driver = webdriver.Firefox(options=options)
        #self.driver.get("https://pythonbasics.org")
        #wd = webdriver.Firefox(service=service, options=options)
        EKO()

    def load(self) :
        self.url = "https://www.bouyguestelecom.fr/tv-direct/#/home"
        bot = self.driver
        browser = self.driver.get(self.url)
        EKOX(browser)
        #browser.implicitly_wait(5)
        time.sleep(4)
        okay = '//*[@class="btn btn-primary btn-lg"]'
        okay = "//button[text()='Okay !']"
        EKO()
        identifiant = '//*[@id="loginWeb"]/div/form/div[1]/div'
        identifiant_xpath = '//*[@id="ID_Authent_Login"]'
        identifiant_area = self.driver.find_element(By.XPATH, identifiant_xpath)
        identifiant_area.send_keys("louis.chevallier@gmail.com")

        mdp = "Bouygues_35"
        mdp_xpath = '//*[@id="ID_Authent_Mdp"]'
        mdp_area = self.driver.find_element(By.XPATH, mdp_xpath)
        mdp_area.send_keys(mdp)
        
        connect_xpath = '//*[@id="loginWeb"]/div/form/div[4]'
        connect_button = self.driver.find_element(By.XPATH, connect_xpath)
        connect_button.click()


        plein_ecran_xpath = '//*[@id="ID_Home_Select_Channel"]'
        plein_ecran_button = self.driver.find_element(By.XPATH, plein_ecran_xpath)
        plein_ecran_button.click()


        
        time.sleep(10000)
        

        
        bot.close()  # shuts down the bot


if __name__ == '__main__':

    parser = argparse.ArgumentParser(
        prog='TV BBox',
        description='xx')
    args = parser.parse_args()
    p = P()
    p.load()

