示例#1
0
def get_drivers(driver, params):
    pilots = []
    pilotList = []
    try:
        print("::: DRIVERS")
        tables = WebDriverWait(
            driver, 30).until(lambda d: d.find_elements_by_xpath("//table"))
        for table in range(0, len(tables)):
            th = tables[table].find_element_by_xpath("./thead/tr/th[1]").text
            if (th == "Teams"):
                tbodys = tables[table].find_elements_by_xpath("./tbody")
                for body in range(0, len(tbodys)):
                    trs = tbodys[body].find_elements_by_xpath("./tr")
                    linkTeam = ""
                    idTeam = ""
                    strTeam = ""
                    for tr in range(0, len(trs)):
                        tds = trs[tr].find_elements_by_xpath("./td")
                        if (tds[0].text != ""):
                            linkTeam = get_link_MSS(tds[0])
                            idTeam = get_id_link_MSS(params["urlBase"],
                                                     linkTeam, "T")
                            strTeam = tds[0].text
                        linkDriver = get_link_MSS(tds[2])
                        idDriver = get_id_link_MSS(params["urlBase"],
                                                   linkDriver, "D")
                        pilot = {
                            "idPlayer":
                            params["catRCtrl"].upper() + "-" + idDriver,
                            "idCategory":
                            params["catRCtrl"],
                            "idRCtrl":
                            idDriver,
                            "idMss":
                            idDriver,
                            "strPlayer":
                            trs[tr].find_element_by_xpath(
                                "./td[3]").text.strip(),
                            "strNumber":
                            trs[tr].find_element_by_xpath(
                                "./td[2]").text.strip(),
                            "idTeam":
                            idTeam,
                            "strTeam":
                            strTeam,
                            "numSeason":
                            parse_int(params["year"]),
                            "strRSS":
                            linkDriver,
                        }
                        if (pilot["idPlayer"] not in pilotList):
                            pilots.append(pilot)
                            pilotList.append(pilot["idPlayer"])
                break
        logger(pilots)
        print("::: PROCESS FINISHED :::")
        return pilots
    except Exception as e:
        logger(e, True, "Drivers", pilots)
        return "::: ERROR DRIVERS :::"
def get_driver_detail(driver, pilot):
    try:
        print("::: DRIVER DETAIL")
        thumb = WebDriverWait(
            driver, 30).until(lambda d: d.find_element_by_xpath(
                "//img[@class='_3nEn_']").get_attribute("src"))
        trs = driver.find_elements_by_xpath("//div[@class='_3wj-5']")
        pilot["strThumb"] = thumb
        pilot["dateBorn"] = trs[0].text
        pilot["strBirthLocation"] = trs[2].text
        pilot["strNationality"] = trs[3].text
        linkCountry = get_link_MSS(trs[3])
        idCountry = get_id_link_MSS(urlBase, linkCountry, "W")
        pilot["intSoccerXMLTeamID"] = idCountry

        social = driver.find_elements_by_xpath("//div[@class='_1MS_T']/a")
        for i in range(0, len(social)):
            link = social[i].get_attribute("href")
            if ("twitter" in link):
                pilot["strTwitter"] = link
            elif ("insta" in link):
                pilot["strInstagram"] = link
            elif ("face" in link):
                pilot["strFacebook"] = link
            elif ("tube" in link):
                pilot["strYoutube"] = link

        print(pilot)
        print("::: PROCESS FINISHED :::")
        return pilot
    except Exception as e:
        print(e)
        return pilot
示例#3
0
def get_champD(driver, params):
    champ = {}
    data = []
    try:
        print("::: CHAMPIONSHIP DRIVERS")
        btn_show = None
        try:
            btn_show = WebDriverWait(driver, 30).until(
                lambda d: d.find_element_by_xpath('//button[@class="hFZZS"]'))
            btn_show.click()
        except Exception as e:
            logger(e, True, "Championship", btn_show)
            pass
        time.sleep(5)
        tables = WebDriverWait(
            driver, 30).until(lambda d: d.find_elements_by_xpath("//table"))
        for table in range(0, len(tables)):
            th = tables[table].find_element_by_xpath("./thead/tr/th[1]").text
            if (th == "Pos."):
                points = 0
                trs = tables[table].find_elements_by_xpath("./tbody/tr")
                for tr in range(0, len(trs)):
                    tds = trs[tr].find_elements_by_xpath("./td")
                    linkDriver = get_link_MSS(tds[1])
                    idDriver = get_id_link_MSS(params["urlBase"], linkDriver,
                                               "D")
                    line = {
                        "idPlayer": idDriver,
                        "position": parse_int(tds[0].text),
                        "totalPoints": parse_float(tds[2].text),
                    }
                    points += line["totalPoints"]
                    data.append(line)
                champ = {
                    "idChamp":
                    params["catRCtrl"].upper() + "-" + params["year"] + "-D",
                    "numSeason": parse_int(params["year"]),
                    "strSeason": params["year"],
                    "idCategory": params["catRCtrl"],
                    "idRCtrl": params["catOrigen"],
                    "idMss": params["catOrigen"],
                    "data": data,
                    "sumPoints": points,
                    "typeChamp": "D"
                }
                break
        logger(champ)
        print("::: PROCESS FINISHED :::")
        return champ
    except Exception as e:
        logger(e, True, "Championship", champ)
        return "::: ERROR CHAMP DRIVERS :::"
示例#4
0
def get_teams(driver, params):
    teams = []
    teamList = []
    try:
        print("::: TEAMS")
        tables = WebDriverWait(
            driver, 30).until(lambda d: d.find_elements_by_xpath("//table"))
        for table in range(0, len(tables)):
            th = tables[table].find_element_by_xpath("./thead/tr/th[1]").text
            if (th == "Teams"):
                tbodys = tables[table].find_elements_by_xpath("./tbody")
                for body in range(0, len(tbodys)):
                    trs = tbodys[body].find_elements_by_xpath("./tr")
                    for tr in range(0, len(trs)):
                        tds = trs[tr].find_elements_by_xpath("./td")
                        if (tds[0].text != ""):
                            linkTeam = get_link_MSS(tds[0])
                            idTeam = get_id_link_MSS(params["urlBase"],
                                                     linkTeam, "T")
                            strTeam = tds[0].text
                            team = {
                                "idTeam":
                                params["catRCtrl"].upper() + "-" +
                                idTeam.strip(),
                                "strTeam":
                                strTeam,
                                "idCategory":
                                params["catRCtrl"],
                                "idRCtrl":
                                idTeam,
                                "idMss":
                                idTeam,
                                "strTeamFanart4":
                                get_brand_logo(strTeam),
                                "numSeason":
                                parse_int(params["year"]),
                                "strGender":
                                "T",
                                "strRSS":
                                linkTeam,
                            }
                            if (team["idTeam"] not in teamList):
                                teams.append(team)
                                teamList.append(team["idTeam"])
                            break
                break
        logger(teams)
        print("::: PROCESS FINISHED :::")
        return teams
    except Exception as e:
        logger(e, True, "Teams", teams)
        return "::: ERROR TEAMS :::"
示例#5
0
def get_champC(driver, params):
    ret = []
    teams = []
    data = []
    champ = {}
    try:
        print("::: CHAMPIONSHIP CONSTRUCTORS")
        btn_show = None
        try:
            btn_show = WebDriverWait(driver, 30).until(
                lambda d: d.find_element_by_xpath('//button[@class="hFZZS"]'))
            btn_show.click()
        except Exception as e:
            logger(e, True, "Championship", btn_show)
            pass
        time.sleep(5)
        tables = WebDriverWait(
            driver, 30).until(lambda d: d.find_elements_by_xpath("//table"))
        pos = 0
        for table in range(0, len(tables)):
            th = tables[table].find_element_by_xpath("./thead/tr/th[1]").text
            if (th == "Pos."):
                if (pos == 0):
                    pos = 1
                    continue
                points = 0
                trs = tables[table].find_elements_by_xpath("./tbody/tr")
                for tr in range(0, len(trs)):
                    tds = trs[tr].find_elements_by_xpath("./td")
                    linkTeam = get_link_CMSS(tds[1])
                    if (linkTeam == ""):
                        idMss = (tds[1].text).lower().replace(" ", "-", 9)
                        idTeam = params["catRCtrl"].upper() + "-C-" + idMss
                        idRCtrl = idTeam
                    else:
                        idMss = get_id_link_MSS(params["urlBase"], linkTeam,
                                                "T")
                        idTeam = params["catRCtrl"].upper() + "-" + idMss
                        idRCtrl = idMss
                    strTeam = tds[1].text
                    team = {
                        "idTeam": idTeam,
                        "strTeam": strTeam,
                        "idCategory": params["catRCtrl"],
                        "idRCtrl": idRCtrl,
                        "idMss": idMss,
                        "numSeason": parse_int(params["year"]),
                        "strTeamFanart4": get_brand_logo(strTeam),
                        "strGender": "C",
                        "strRSS": linkTeam
                    }
                    teams.append(team)
                    line = {
                        "idPlayer": idRCtrl,
                        "position": parse_int(tds[0].text),
                        "totalPoints": parse_float(tds[2].text),
                    }
                    points += line["totalPoints"]
                    data.append(line)
                champ = {
                    "idChamp":
                    params["catRCtrl"].upper() + "-" + params["year"] + "-C",
                    "numSeason": parse_int(params["year"]),
                    "strSeason": params["year"],
                    "idCategory": params["catRCtrl"],
                    "idRCtrl": params["catOrigen"],
                    "idMss": params["catOrigen"],
                    "data": data,
                    "sumPoints": points,
                    "typeChamp": "C"
                }
                ret.append(teams)
                ret.append(champ)
                break
        logger(ret)
        print("::: PROCESS FINISHED :::")
        return ret
    except Exception as e:
        logger(e, True, "Championship", [teams, champ])
        return "::: ERROR CHAMP CONSTRUCTORS :::"
示例#6
0
def get_events(driver, params):
    events = []
    try:
        print("::: EVENTS")
        tables = WebDriverWait(
            driver, 30).until(lambda d: d.find_elements_by_xpath("//table"))
        for table in range(0, len(tables)):
            th = tables[table].find_element_by_xpath("./thead/tr/th[1]").text
            if (th == "#"):
                trs = tables[table].find_elements_by_xpath("./tbody/tr")
                for tr in range(0, len(trs)):
                    tds = trs[tr].find_elements_by_xpath("./td")
                    linkEvent = get_link_MSS(tds[2])
                    idEvent = get_id_link_MSS(params["urlBase"], linkEvent,
                                              "E")
                    linkCircuit = get_link_MSS(tds[3])
                    idCircuit = get_id_link_MSS(params["urlBase"], linkCircuit,
                                                "C")
                    linkDriver = get_link_MSS(tds[4])
                    idDriver = get_id_link_MSS(params["urlBase"], linkDriver,
                                               "D")
                    strEvent = tds[2].text
                    strPostponed = ""
                    if (tds[1].text == "TBC"):
                        strPostponed = "TBC"
                    if ("Cancelled" in strEvent):
                        strEvent = strEvent.replace(" - Cancelled",
                                                    "").replace(
                                                        "Cancelled", "")
                        strPostponed = "Cancelled"
                    event = {
                        "idEvent":
                        params["catRCtrl"].upper() + "-" + tds[0].text + "-" +
                        idEvent.strip(),
                        "strEvent":
                        strEvent,
                        "idCategory":
                        params["catRCtrl"],
                        "idRCtrl":
                        idEvent,
                        "idMss":
                        idEvent,
                        "intRound":
                        tds[0].text,
                        "strDate":
                        tds[1].text,
                        "idWinner":
                        idDriver,
                        "strResult":
                        tds[4].text,
                        "idCircuit":
                        idCircuit,
                        "strCircuit":
                        tds[3].text,
                        "numSeason":
                        parse_int(params["year"]),
                        "strSeason":
                        params["year"],
                        "strPostponed":
                        strPostponed,
                        "strRSS":
                        linkEvent,
                    }
                    events.append(event)
                break
        logger(events)
        print("::: PROCESS FINISHED :::")
        return events
    except Exception as e:
        logger(e, True, "Events", events)
        return "::: ERROR EVENTS :::"