Exemple #1
0
def getMore(search):
    driver.execute_script("window.open('https://google.com')")
    driver.switch_to.window(driver.window_handles[-1])
    try :
        input_element = WDW(driver, 2).until(poel((By.NAME, "q")))
    finally:
        pass
    input_element.send_keys(search)
    input_element.submit()
    try:
        link = WDW(driver, 2).until(poel((By.XPATH, "//div/a/h3")))
    finally:
        link.click()
    try:
        try:
            okay = WDW(driver, 2).until(poel((By.XPATH, '//*[@id="didomi-notice-agree-button"]')))
        finally:
            okay.click()
    except:
        pass
    goalLists = driver.find_elements_by_xpath("//*[contains(@class, 'Scoreboard__goalList')]")

    homeTable = goalLists[0].find_elements_by_xpath("*")
    awayTable = goalLists[1].find_elements_by_xpath("*")
    
    HT = 0
    HC = 0
    HP = 0
    AT = 0
    AC = 0
    AP = 0

    for i in homeTable:
        txt = i.get_attribute('innerText')
        if 'essais' in txt:
            HT = int(txt.split('\n')[0])
        if 'transf' in txt:
            HC = int(txt.split('\n')[0])
        if 'pénali' in txt:
            HP = int(txt.split('\n')[0])

    for i in awayTable:
        txt = i.get_attribute('innerText')
        if 'essais' in txt:
            AT = int(txt.split('\n')[0])
        if 'transf' in txt:
            AC = int(txt.split('\n')[0])
        if 'pénali' in txt:
            AP = int(txt.split('\n')[0])
    
    driver.close()
    driver.switch_to.window(driver.window_handles[0])
    time.sleep(5)
    return (HT, HC, HP, AT, AC, AP)
Exemple #2
0
def drive_browser(infoDict):
    # count = 0

    name = "NA"
    for key in infoDict:
        try:
            driver = webdriver.Chrome(executable_path="/usr/bin/chromedriver")
            wait = WebDriverWait(driver, 10)
            driver.get(cgpa_uri)

            driver.find_element_by_xpath("//input[@name='search']").send_keys(
                key)

            driver.find_element_by_xpath(
                "//button[@class='searchButton']").click()

            generator = wait.until(
                poel((By.XPATH, "//section[@id='portfolio']/div/div/div[1]")))

            txt = generator.text.split('\n')
            if len(txt) > 1:
                joinString = txt[2]
                joinString = joinString.split(":")
                name = joinString[1].strip()
                # print(f"{name}")  # print statement here
                # count += 1
            infoDict[key]['name'] = name

            driver.close()

        except Exception as e:
            errors.append(e)
Exemple #3
0
 def get_wait(self, elem_name, wait_timeout=None):
     if wait_timeout is None:
         wait_timeout = self.timeout
     try:
         wait(self.driver,
              wait_timeout).until(poel((By.CLASS_NAME, elem_name)))
         return True
     except To:
         return False
Exemple #4
0
I_ATEAM = 13



options = webdriver.ChromeOptions()

driver = webdriver.Chrome(options=options)
driver.get("https://www.google.com/webhp?hl=en&gl=en")
input_element = driver.find_element_by_name("q")
input_element.send_keys('schedule ' + LEAGUE)
input_element.submit()

RESULTS_LOCATOR = "//div/h3/a"

try:
    frame = WDW(driver, 2).until(poel((By.XPATH, "//iframe[contains(@src, 'consent.google.com')]")))
finally:
    driver.switch_to_frame(frame)
driver.find_element_by_xpath('//*[@id="introAgreeButton"]/span/span').click()
try:
    WDW(driver, 2).until(poel((By.XPATH, "//div[contains(@class, 'imso-loa') and contains(@class, 'imso-ani')]")))
finally:
    driver.find_elements_by_xpath("//div[contains(@class, 'imso-loa') and contains(@class, 'imso-ani')]")[-1].click()

time.sleep(2)

actions = ActionChains(driver)

for loop in range(4):
    first = driver.find_elements_by_xpath("//div[contains(@class, 'imso-loa') and contains(@class, 'imso-ani')]")[0]
    actions.move_to_element(first).perform()
Exemple #5
0
def verifyTeams(leagueIdentifier):
    cleanScreen()
    indication = Label(frame,
                       text="Please wait while google names get fetched")
    indication.pack()
    leagueIdent = leagueIdentifier
    with open('leagues.json', 'r') as f:
        allTeamIds = json.load(f)

    teamIds = allTeamIds[leagueIdentifier]

    LEAGUE = teamIds['_leagueName']

    driver = webdriver.Chrome()
    driver.get("https://www.google.com/webhp?hl=en&gl=en")
    input_element = driver.find_element_by_name("q")
    input_element.send_keys(LEAGUE)
    input_element.submit()

    RESULTS_LOCATOR = "//div/h3/a"

    try:
        frameWeb = WDW(driver, 2).until(
            poel((By.XPATH, "//iframe[contains(@src, 'consent.google.com')]")))
    finally:
        driver.switch_to.frame(frameWeb)
    driver.find_element_by_xpath(
        '//*[@id="introAgreeButton"]/span/span').click()
    try:
        try:
            WDW(driver,
                2).until(poel((By.XPATH, "//li[@data-tab_type='STANDINGS']")))
        finally:
            driver.find_element_by_xpath(
                "//li[@data-tab_type='STANDINGS']").click()
            verifyFailed = False
    except:
        indication.destroy()
        verifyFailed = True
        askYesNo(
            'Seems like google does not have any data for this league\nWould you like to erase that league from the json ?',
            deleteLeagueTeams, [leagueIdentifier])
        driver.quit()
    if verifyFailed:
        return
    indication.destroy()
    indication = Label(
        frame,
        text=
        "Please click on a name in each list, then click on pair.\nYou can also clic on an element from the pair list and unpair it."
    )
    indication.grid(row=0, columnspan=2)
    time.sleep(1)
    liste = driver.find_elements_by_xpath("//*[@class='e6E1Yd']")
    names = []
    for i in liste:
        names.append(i.get_attribute('innerText').split('\n')[0])

    driver.quit()

    names.sort()

    teams = {}
    teams['_leagueName'] = LEAGUE
    teams['_verified'] = 'True'
    for i in teamIds:
        if not i in ['_leagueName', '_verified']:
            teams[i] = teamIds[i]

    dataNamesBox = Listbox(frame)
    dataNamesBox.grid(row=1, column=0, pady=10)
    for tea in teams:
        if not tea in ['_leagueName', '_verified']:
            dataNamesBox.insert(END, tea)

    googleNamesBox = Listbox(frame)
    googleNamesBox.grid(row=1, column=1, pady=10)
    for name in names:
        googleNamesBox.insert(END, name)

    pairButton = Button(
        frame,
        text='Pair',
        command=lambda: validatePair(dataNamesBox, googleNamesBox, pairsBox,
                                     teams, allTeamIds, leagueIdent))
    pairButton.grid(row=2, columnspan=2)

    pairsBox = Listbox(frame)
    pairsBox.config(width=80)
    pairsBox.grid(row=4, columnspan=2, pady=10)

    unpairButton = Button(frame,
                          text='Unpair',
                          command=lambda: validateUnpair(
                              dataNamesBox, googleNamesBox, pairsBox, teams))
    unpairButton.grid(row=5, columnspan=2)
Exemple #6
0
def downloadLeagueSchedule(leagueIdentifier):
    cleanScreen()
    with open('leagues.json', 'r') as f:
        allTeamIds = json.load(f)

    teamIds = allTeamIds[leagueIdentifier]

    LEAGUE = teamIds['_leagueName']

    LENGTH_FINISHED = 5

    I_F_DATE = 0
    I_F_HTEAM = 2
    I_F_HSCORE = 1
    I_F_ATEAM = 4
    I_F_ASCORE = 3

    I_DATE = 0
    I_TIME = 1
    I_HTEAM = 2
    I_ATEAM = 3

    options = webdriver.ChromeOptions()

    driver = webdriver.Chrome(options=options)
    driver.get("https://www.google.com/webhp?hl=en&gl=en")
    input_element = driver.find_element_by_name("q")
    input_element.send_keys(LEAGUE)
    input_element.submit()

    RESULTS_LOCATOR = "//div/h3/a"

    try:
        frame = WDW(driver, 2).until(
            poel((By.XPATH, "//iframe[contains(@src, 'consent.google.com')]")))
    finally:
        driver.switch_to.frame(frame)
    driver.find_element_by_xpath(
        '//*[@id="introAgreeButton"]/span/span').click()
    try:
        WDW(driver, 2).until(
            poel((
                By.XPATH,
                "//div[contains(@class, 'imso-loa') and contains(@class, 'imso-ani')]"
            )))
    finally:
        driver.find_elements_by_xpath(
            "//div[contains(@class, 'imso-loa') and contains(@class, 'imso-ani')]"
        )[-1].click()

    time.sleep(2)

    actions = ActionChains(driver)

    for loop in range(4):
        first = driver.find_elements_by_xpath(
            "//div[contains(@class, 'imso-loa') and contains(@class, 'imso-ani')]"
        )[0]
        actions.move_to_element(first).perform()
        time.sleep(1)

    for loop in range(4):
        liste = driver.find_elements_by_xpath(
            "//div[contains(@class, 'imso-loa') and contains(@class, 'imso-ani')]"
        )
        last = liste[int(len(liste) - 10)]
        actions.move_to_element(last).perform()
        time.sleep(1)

    time.sleep(2)
    liste = driver.find_elements_by_xpath(
        "//div[contains(@class, 'imso-loa') and contains(@class, 'imso-ani')]")

    with open('tables/' + LEAGUE + '.csv', 'wb') as csvfile:
        writer = csv.writer(csvfile,
                            delimiter=',',
                            quotechar='"',
                            quoting=csv.QUOTE_MINIMAL)
        for match in liste:
            strL = match.get_attribute('innerText').splitlines()
            strStart = match.get_attribute('data-start-time')
            strDate = ''
            strTime = ''
            if not (strStart == None):
                try:
                    strDate = strStart.split('T')[0]
                    strTime = strStart.split('T')[1][:-1]
                except:
                    print('strStart Error:', strStart)
            try:
                strL = clean(strL)
                if len(strL) > 5:
                    print('Unwanted item in the list :', repr(strL))
                    continue
                if len(strL) > 1:
                    if len(strL) == LENGTH_FINISHED:
                        writer.writerow([
                            strDate, strTime, strL[I_F_HTEAM],
                            teamIds[strL[I_F_HTEAM]],
                            cleanScore(strL[I_F_HSCORE]), strL[I_F_ATEAM],
                            teamIds[strL[I_F_ATEAM]],
                            cleanScore(strL[I_F_ASCORE])
                        ])
                    else:
                        writer.writerow([
                            strDate, strTime, strL[I_HTEAM],
                            teamIds[strL[I_HTEAM]], '', strL[I_ATEAM],
                            teamIds[strL[I_ATEAM]], ''
                        ])

            except:
                print('Unwanted item in the list :', repr(strL))
    time.sleep(2)
    driver.quit()