Пример #1
0
def create_APTP(params):
    ret = {}

    driver = run_chrome()

    url = "/calendario-" + params["year"] + "/"
    driver.get(params["urlBase"] + url)

    time.sleep(5)
    e_scrap = get_events(driver, params)
    # ret["events"] = e_scrap
    c_base = api_request(
        "get", params["urlApi"] + "/circuit/ids/aptp")
    c_clean = clean_duplicate("idCircuit", e_scrap[0], c_base)
    ret["circuits"] = api_request(
        "post", params["urlApi"] + "/circuit/create", c_clean)

    time.sleep(5)
    e_base = api_request("get", params["urlApi"] + "/event/ids/" + params["catId"]
                         + "/" + params["year"])
    e_clean = clean_duplicate("idEvent", e_scrap[1], e_base)
    ret["events"] = api_request(
        "post", params["urlApi"] + "/event/create", e_clean)

    # url = "/pilotos-" + params["catOrigen"] + "/"
    # driver.get(params["urlBase"] + url)

    # d_scrap = get_drivers(driver, params)
    # # ret["drivers"] = d_scrap

    url = "/campeonato-" + params["catOrigen"] + "/"
    driver.get(params["urlBase"] + url)

    time.sleep(5)
    chd_scrap = get_champD(driver, params)
    # ret["champD"] = chd_scrap
    d_base = api_request("get", params["urlApi"] + "/driver/ids/" + params["catId"]
                         + "/" + params["year"])
    d_clean = clean_duplicate("idPlayer", chd_scrap[0], d_base)
    # ret["drivers"] = api_request(
    #     "post", params["urlApi"]+"/driver/create", d_clean)
    ret["drivers"] = api_request(
        "put", params["urlApi"] + "/driver/update/0", d_clean)

    # d_base = api_request("get", params["urlApi"]+"/driver/ids/"+params["catId"]
    #                      + "/" + params["year"])
    # d_clean = clean_duplicate("idPlayer", d_scrap, d_base)
    # ret["drivers_extra"] = api_request(
    #     "post", params["urlApi"]+"/driver/create", d_clean)

    time.sleep(5)
    ch_base = api_request("get", params["urlApi"] + "/champ/ids/" + params["catId"]
                          + "/" + params["year"])
    chd_clean = clean_duplicate_ch("idChamp", chd_scrap[1], ch_base)
    ret["champD"] = api_request(
        "post", params["urlApi"] + "/champ/create", chd_clean)

    driver.close()

    return ret
Пример #2
0
def create_AUVO(params):
    ret = {}

    driver = run_chrome()

    url = "/calendario"
    driver.get(params["urlBase"] + url)

    e_scrap = get_events(driver, params)
    # ret["circuits"] = e_scrap[0]
    # ret["events"] = e_scrap[1]
    c_base = api_request("get", params["urlApi"] + "/circuit/ids/auvo")
    c_clean = clean_duplicate("idCircuit", e_scrap[0], c_base)
    ret["circuits"] = api_request("post", params["urlApi"] + "/circuit/create",
                                  c_clean)

    time.sleep(5)
    e_base = api_request(
        "get", params["urlApi"] + "/event/ids/" + params["catId"] + "/" +
        params["year"])
    e_clean = clean_duplicate("idEvent", e_scrap[1], e_base)
    ret["events"] = api_request("post", params["urlApi"] + "/event/create",
                                e_clean)

    driver.close()

    return ret
Пример #3
0
def run_script_CUR(params):
    ret = {}

    driver = run_chrome()
    url = "http://www.rally.org.uy/rallylive/2020/1/PE1.html"
    driver.get(url)

    d_scrap = get_drivers(driver, params)
    # ret["drivers"] = d_scrap
    d_base = api_request(
        "get", params["urlApi"] + "/driver/ids/" + params["catId"] + "/" +
        params["year"])
    d_clean = clean_duplicate("idPlayer", d_scrap, d_base)
    # ret["drivers"] = api_request(
    #     "post", params["urlApi"]+"/driver/create", d_clean)
    ret["drivers"] = api_request("put", params["urlApi"] + "/driver/update/0",
                                 d_clean)

    url = "https://www.cur.com.uy/calendario-" + params["year"]
    driver.get(url)

    time.sleep(5)
    e_scrap = get_events(driver, params)
    # ret["events"] = events
    c_base = api_request("get", params["urlApi"] + "/circuit/ids/cur")
    c_clean = clean_duplicate("idCircuit", e_scrap[0], c_base)
    ret["circuits"] = api_request("post", params["urlApi"] + "/circuit/create",
                                  c_clean)

    time.sleep(5)
    e_base = api_request(
        "get", params["urlApi"] + "/event/ids/" + params["catId"] + "/" +
        params["year"])
    e_clean = clean_duplicate("idEvent", e_scrap[1], e_base)
    ret["events"] = api_request("post", params["urlApi"] + "/event/create",
                                e_clean)

    # url = "/campeonato-" + catOrigen + "/"
    # driver.get(urlBase + url)

    # time.sleep(5)
    # champ = get_champD(driver, params)
    # # ret["champD"] = champ
    # ret["drivers_extra"] = api_request(
    # "post",urlApi+"/driver/create", champ[0])

    # time.sleep(5)
    # ret["champD"] = api_request("post",urlApi+"/champ/create", champ[1])

    driver.close()

    return ret
Пример #4
0
def run_script_AUVOCat(params):
    ret = {}

    driver = run_chrome()

    url = "https://speedhive.mylaps.com/Sessions/5866106"

    driver.get("https://speedhive.mylaps.com")
    driver.get("https://speedhive.mylaps.com/Organizations/95827")
    driver.get("https://speedhive.mylaps.com/Events/1814191")
    if (params["catRCtrl"] == 'uyst'):
        driver.get(url + "5866106")
    elif (params["catRCtrl"] == 'uyse'):
        driver.get(url + "5866101")
    elif (params["catRCtrl"] == 'uyth'):
        driver.get(url + "5865717")
    elif (params["catRCtrl"] == 'uyss'):
        driver.get(url + "5865709")
    else:
        driver.close()
        return ret

    d_scrap = get_drivers(driver, params)
    # ret["drivers"] = data
    d_base = api_request(
        "get", params["urlApi"] + "/driver/ids/" + params["catId"] + "/" +
        params["year"])
    d_clean = clean_duplicate("idPlayer", d_scrap, d_base)
    # ret["drivers"] = api_request(
    #     "post", params["urlApi"]+"/driver/create", d_clean)
    ret["drivers"] = api_request("put", params["urlApi"] + "/driver/update/0",
                                 d_clean)

    # time.sleep(5)
    # t_data = get_teams(driver, params)
    # ret["teams"] = api_request(
    # "post", params["urlApi"]+"/team/create", t_data)

    ans = create_AUVO(params)
    ret["events"] = ans

    driver.close()

    return ret
Пример #5
0
def update_TR(params):
    ret = {}

    # CHAMPIONSHIPS
    driver = run_chrome()

    chd_base = api_request(
        "get", params["urlApi"] + "/champ/cat/" + params["catId"] + "/" +
        params["year"] + "/D")

    url = "/campeonato-general/" + params["year"] + ".html"
    driver.get(params["urlBase"] + "/" + params["catOrigen"] + url)

    time.sleep(3)
    if (chd_base):
        champId = chd_base["_id"]
        sumPoints = chd_base.get("sumPoints", 0)
        chd_scrap = get_champD(driver, params)
        if (len(chd_scrap) > 0 and chd_scrap.get("sumPoints", 0) > sumPoints):
            ret["champD"] = api_request(
                "put", params["urlApi"] + "/champ/update/" + champId,
                chd_scrap)

    # EVENTS AND CIRCUITS
    if (params["updType"] == "events" or params["updType"] == "all"):
        time.sleep(3)
        e_base = api_request(
            "get", params["urlApi"] + "/event/cat/" + params["catId"] + "/" +
            params["year"])

        url = "/calendario/" + params["year"] + ".html"
        driver.get(params["urlBase"] + "/" + params["catOrigen"] + url)

        e_scrap = get_events(driver, params)

        ret["events"] = e_base

        time.sleep(3)
        c_base = api_request("get", params["urlApi"] + "/circuit/ids/toprace")
        c_clean = clean_duplicate("idCircuit", e_scrap[0], c_base)
        ret["circuits"] = api_request("post",
                                      params["urlApi"] + "/circuit/create",
                                      c_clean)

        compared = compareEvents(e_base, e_scrap[1])
        ret["compared"] = compared

        if (len(compared["news"]) > 0):
            time.sleep(5)
            ret["newEvents"] = api_request("post",
                                           params["urlApi"] + "/event/create",
                                           compared["news"])

        upds = compared["updated"]
        clds = compared["cancelled"]
        items = []
        for it in range(0, len(upds)):
            time.sleep(2)
            items.append(
                api_request(
                    "put",
                    params["urlApi"] + "/event/update/" + upds[it]["id"],
                    upds[it]["new"]))
        for it in range(0, len(clds)):
            time.sleep(2)
            items.append(
                api_request(
                    "put",
                    params["urlApi"] + "/event/update/" + clds[it]["id"],
                    clds[it]["new"]))
        ret["updEvents"] = items

    # DRIVERS AND TEAMS
    if (params["updType"] == "drivers" or params["updType"] == "all"):
        time.sleep(5)
        url = "/equipos.html"
        driver.get(params["urlBase"] + "/" + params["catOrigen"] + url)

        t_scrap = get_teams(driver, params)
        ret["teams"] = api_request("put", params["urlApi"] + "/team/update/0",
                                   t_scrap)

        url = "/pilotos.html"
        driver.get(params["urlBase"] + "/" + params["catOrigen"] + url)

        time.sleep(3)
        d_scrap = get_drivers(driver, params, t_scrap)
        ret["drivers"] = api_request("put",
                                     params["urlApi"] + "/driver/update/0",
                                     d_scrap)

    driver.close()

    return ret
Пример #6
0
def create_TR(params):
    ret = {}

    driver = run_chrome()

    url = "/equipos.html"
    driver.get(params["urlBase"] + "/" + params["catOrigen"] + url)

    t_scrap = get_teams(driver, params)
    t_base = api_request(
        "get", params["urlApi"] + "/team/ids/" + params["catId"] + "/" +
        params["year"])
    t_clean = clean_duplicate("idTeam", t_scrap, t_base)
    # ret["teams"] = api_request(
    #     "post", params["urlApi"] + "/team/create", t_clean)
    ret["teams"] = api_request("put", params["urlApi"] + "/team/update/0",
                               t_clean)

    url = "/pilotos.html"
    driver.get(params["urlBase"] + "/" + params["catOrigen"] + url)

    time.sleep(5)
    d_scrap = get_drivers(driver, params, t_scrap)
    d_base = api_request(
        "get", params["urlApi"] + "/driver/ids/" + params["catId"] + "/" +
        params["year"])
    d_clean = clean_duplicate("idPlayer", d_scrap, d_base)
    # ret["drivers"] = api_request(
    #     "post", params["urlApi"]+"/driver/create", d_clean)
    ret["drivers"] = api_request("put", params["urlApi"] + "/driver/update/0",
                                 d_clean)

    url = "/calendario/" + params["year"] + ".html"
    driver.get(params["urlBase"] + "/" + params["catOrigen"] + url)

    time.sleep(5)
    e_scrap = get_events(driver, params)
    c_base = api_request("get", params["urlApi"] + "/circuit/ids/toprace")
    c_clean = clean_duplicate("idCircuit", e_scrap[0], c_base)
    ret["circuits"] = api_request("post", params["urlApi"] + "/circuit/create",
                                  c_clean)

    time.sleep(5)
    e_base = api_request(
        "get", params["urlApi"] + "/event/ids/" + params["catId"] + "/" +
        params["year"])
    e_clean = clean_duplicate("idEvent", e_scrap[1], e_base)
    ret["events"] = api_request("post", params["urlApi"] + "/event/create",
                                e_clean)

    url = "/campeonato-general/" + params["year"] + ".html"
    driver.get(params["urlBase"] + "/" + params["catOrigen"] + url)

    time.sleep(5)
    chd_scrap = get_champD(driver, params)
    ch_base = api_request(
        "get", params["urlApi"] + "/champ/ids/" + params["catId"] + "/" +
        params["year"])
    ch_clean = clean_duplicate_ch("idChamp", chd_scrap, ch_base)
    ret["champD"] = api_request("post", params["urlApi"] + "/champ/create",
                                ch_clean)

    driver.close()

    return ret
Пример #7
0
def create_APAT(params):
    ret = {}

    driver = run_chrome()

    url = "/pilotoslistado" + "/" + params["catOrigen"]
    driver.get(params["urlBase"] + url)

    d_scrap = get_drivers(driver, params)
    # ret["drivers"] = pilots
    d_base = api_request(
        "get", params["urlApi"] + "/driver/ids/" + params["catId"] + "/" +
        params["year"])
    d_clean = clean_duplicate("idPlayer", d_scrap[0], d_base)

    time.sleep(2)
    t_scrap = get_teams(d_scrap[0], params)
    # ret["teams"] = t_scrap
    t_base = api_request(
        "get", params["urlApi"] + "/team/ids/" + params["catId"] + "/" +
        params["year"])
    t_clean = clean_duplicate("idTeam", t_scrap, t_base)
    # ret["teams"] = api_request(
    #     "post", params["urlApi"] + "/team/create", t_clean)
    ret["teams"] = api_request("put", params["urlApi"] + "/team/update/0",
                               t_clean)

    time.sleep(5)
    # ret["drivers"] = api_request(
    #     "post", params["urlApi"] + "/driver/create", d_clean)
    ret["drivers"] = api_request("put", params["urlApi"] + "/driver/update/0",
                                 d_clean)

    time.sleep(5)
    ch_base = api_request(
        "get", params["urlApi"] + "/champ/ids/" + params["catId"] + "/" +
        params["year"])
    chd_clean = clean_duplicate_ch("idChamp", d_scrap[1], ch_base)
    ret["champD"] = api_request("post", params["urlApi"] + "/champ/create",
                                chd_clean)

    url = "/calendario/" + params["year"]
    driver.get(params["urlBase"] + url)

    time.sleep(5)
    e_scrap = get_events(driver, params)
    # ret["events"] = events
    e_base = api_request(
        "get", params["urlApi"] + "/event/ids/" + params["catId"] + "/" +
        params["year"])
    e_clean = clean_duplicate("idEvent", e_scrap, e_base)

    url = "/circuitos/todos"
    driver.get(params["urlBase"] + url)

    time.sleep(3)
    c_scrap = get_circuits(driver, params)
    # ret["circuits"] = circuits
    c_base = api_request("get", params["urlApi"] + "/circuit/ids/apat")
    c_clean = clean_duplicate("idCircuit", c_scrap, c_base)

    ret["circuits"] = api_request("post", params["urlApi"] + "/circuit/create",
                                  c_clean)

    time.sleep(3)
    ret["events"] = api_request("post", params["urlApi"] + "/event/create",
                                e_clean)

    driver.close()

    return ret
Пример #8
0
def update_APAT(params):
    ret = {}

    driver = run_chrome()

    # DRIVERS AND TEAMS
    time.sleep(5)
    url = "/pilotoslistado" + "/" + params["catOrigen"]
    driver.get(params["urlBase"] + url)

    d_scrap = get_drivers(driver, params)
    t_scrap = get_teams(d_scrap[0], params)

    ret["teams"] = api_request("put", params["urlApi"] + "/team/update/0",
                               t_scrap)

    time.sleep(3)
    ret["drivers"] = api_request("put", params["urlApi"] + "/driver/update/0",
                                 d_scrap[0])

    # CHAMPIONSHIPS
    chd_base = api_request(
        "get", params["urlApi"] + "/champ/cat/" + params["catId"] + "/" +
        params["year"] + "/D")

    time.sleep(3)
    if (chd_base):
        champId = chd_base["_id"]
        sumPoints = chd_base.get("sumPoints", 0)
        if (len(d_scrap[1]) > 0
                and d_scrap[1].get("sumPoints", 0) > sumPoints):
            ret["champD"] = api_request(
                "put", params["urlApi"] + "/champ/update/" + champId,
                d_scrap[1])

    # EVENTS AND CIRCUITS
    if (params["updType"] == "events" or params["updType"] == "all"):

        url = "/circuitos/todos"
        driver.get(params["urlBase"] + url)

        time.sleep(3)
        c_scrap = get_circuits(driver, params)

        c_base = api_request("get", params["urlApi"] + "/circuit/ids/apat")
        c_clean = clean_duplicate("idCircuit", c_scrap, c_base)
        ret["circuits"] = api_request("post",
                                      params["urlApi"] + "/circuit/create",
                                      c_clean)

        time.sleep(3)
        e_base = api_request(
            "get", params["urlApi"] + "/event/cat/" + params["catId"] + "/" +
            params["year"])

        url = "/calendario/" + params["year"]
        driver.get(params["urlBase"] + url)

        e_scrap = get_events(driver, params)

        ret["events"] = e_base

        compared = compareEvents(e_base, e_scrap)
        ret["compared"] = compared

        if (len(compared["news"]) > 0):
            time.sleep(5)
            ret["newEvents"] = api_request("post",
                                           params["urlApi"] + "/event/create",
                                           compared["news"])

        upds = compared["updated"]
        clds = compared["cancelled"]
        items = []
        for it in range(0, len(upds)):
            time.sleep(2)
            items.append(
                api_request(
                    "put",
                    params["urlApi"] + "/event/update/" + upds[it]["id"],
                    upds[it]["new"]))
        for it in range(0, len(clds)):
            time.sleep(2)
            items.append(
                api_request(
                    "put",
                    params["urlApi"] + "/event/update/" + clds[it]["id"],
                    clds[it]["new"]))
        ret["updEvents"] = items

    driver.close()

    return ret
Пример #9
0
def run_script_MSS(params):
    ret = {}
    try:
        if (parse_int(params["year"]) >= params["chYearIni"]
                and parse_int(params["year"]) <= params["chYearFin"]):

            driver = run_chrome()

            url = "/series/" + params["catOrigen"] + \
                "/season/" + params["year"] + ""
            driver.get(params["urlBase"] + url)

            d_scrap = get_drivers(driver, params)
            d_base = api_request(
                "get", params["urlApi"] + "/driver/ids/" + params["catId"] +
                "/" + params["year"])
            d_clean = clean_duplicate("idPlayer", d_scrap, d_base)

            time.sleep(2)
            t_scrap = get_teams(driver, params)
            t_base = api_request(
                "get", params["urlApi"] + "/team/ids/" + params["catId"] +
                "/" + params["year"])
            t_clean = clean_duplicate("idTeam", t_scrap, t_base)
            # ret["teams"] = api_request(
            #     "post", params["urlApi"] + "/team/create", t_clean)
            ret["teams"] = api_request("put",
                                       params["urlApi"] + "/team/update/0",
                                       t_clean)

            time.sleep(5)
            # ret["drivers"] = api_request(
            #     "post", params["urlApi"] + "/driver/create", d_clean)
            ret["drivers"] = api_request("put",
                                         params["urlApi"] + "/driver/update/0",
                                         d_clean)

            time.sleep(5)
            e_scrap = get_events(driver, params)
            c_scrap = run_script_circuits(driver, params, e_scrap)
            c_base = api_request("get", params["urlApi"] + "/circuit/ids/mss")
            c_clean = clean_duplicate("idCircuit", c_scrap, c_base)
            ret["circuits"] = api_request("post",
                                          params["urlApi"] + "/circuit/create",
                                          c_clean)

            time.sleep(5)
            e_base = api_request(
                "get", params["urlApi"] + "/event/ids/" + params["catId"] +
                "/" + params["year"])
            e_clean = clean_duplicate("idEvent", e_scrap, e_base)
            ret["events"] = api_request("post",
                                        params["urlApi"] + "/event/create",
                                        e_clean)

            time.sleep(5)
            ch_base = api_request(
                "get", params["urlApi"] + "/champ/ids/" + params["catId"] +
                "/" + params["year"])
            if ("D" in params["chTypes"]):
                chd_scrap = get_champD(driver, params)
                chd_clean = clean_duplicate_ch("idChamp", chd_scrap, ch_base)
                ret["champD"] = api_request("post",
                                            params["urlApi"] + "/champ/create",
                                            chd_clean)

            if ("C" in params["chTypes"]):
                time.sleep(5)
                t_base = api_request(
                    "get", params["urlApi"] + "/team/ids/" + params["catId"] +
                    "/" + params["year"])
                chc_scrap = get_champC(driver, params)
                tc_clean = clean_duplicate("idTeam", chc_scrap[0], t_base)
                chc_clean = clean_duplicate_ch("idChamp", chc_scrap[1],
                                               ch_base)
                # # ret["champC"] = chc_clean
                # ret["teamsC"] = api_request(
                #     "post", params["urlApi"] + "/team/create", tc_clean)
                ret["teamsC"] = api_request(
                    "put", params["urlApi"] + "/team/update/0", tc_clean)

                time.sleep(5)
                ret["champC"] = api_request("post",
                                            params["urlApi"] + "/champ/create",
                                            chc_clean)

            if ("T" in params["chTypes"]):
                time.sleep(5)
                cdd_scrap = get_champT(driver, params)
                chd_clean = clean_duplicate_ch("idChamp", cdd_scrap, ch_base)
                # ret["champT"] = chd_clean
                ret["champT"] = api_request("post",
                                            params["urlApi"] + "/champ/create",
                                            chd_clean)

            driver.close()
    except Exception as e:
        logger(e, True, "Script", params)
        return "::: ERROR SCRIPT :::"

    return ret
Пример #10
0
def run_script_GPU(params):
    ret = {}

    driver = run_chrome()

    url = "/edicion/" + params["year"] + "/lista-de-inscriptos"
    driver.get(params["urlBase"] + url)

    d_scrap = get_drivers(driver, params)
    # ret["drivers"] = d_scrap
    t_scrap = get_teams(d_scrap, params)
    # ret["teams"] = t_scrap
    t_base = api_request(
        "get", params["urlApi"] + "/team/ids/" + params["catId"] + "/" +
        params["year"])
    t_clean = clean_duplicate("idTeam", t_scrap, t_base)
    # ret["teams"] = api_request(
    #     "post", params["urlApi"] + "/team/create", t_clean)
    ret["teams"] = api_request("put", params["urlApi"] + "/team/update/0",
                               t_clean)

    time.sleep(5)
    d_base = api_request(
        "get", params["urlApi"] + "/driver/ids/" + params["catId"] + "/" +
        params["year"])
    d_clean = clean_duplicate("idPlayer", d_scrap, d_base)
    # ret["drivers"] = api_request(
    #     "post", params["urlApi"]+"/driver/create", d_clean)
    ret["drivers"] = api_request("put", params["urlApi"] + "/driver/update/0",
                                 d_clean)

    url = "/edicion/" + params["year"] + "/rutas-y-etapas"
    driver.get(params["urlBase"] + url)

    e_scrap = get_events(driver, params)
    # ret["events"] = events
    time.sleep(5)
    c_base = api_request("get", params["urlApi"] + "/circuit/ids/gpu")
    c_clean = clean_duplicate("idCircuit", e_scrap[0], c_base)
    ret["circuits"] = api_request("post", params["urlApi"] + "/circuit/create",
                                  c_clean)

    time.sleep(5)
    e_base = api_request(
        "get", params["urlApi"] + "/event/ids/" + params["catId"] + "/" +
        params["year"])
    e_clean = clean_duplicate("idEvent", e_scrap[1], e_base)
    ret["events"] = api_request("post", params["urlApi"] + "/event/create",
                                e_clean)

    # url = "/" + params["catOrigen"] + "/campeonato/" + params["year"] + ".html"
    # driver.get(params["urlBase"] + url)

    # time.sleep(5)
    # ch_base = api_request("get", params["urlApi"]+"/champ/ids/"+params["catId"]
    #                       + "/" + params["year"])
    # chd_scrap = get_champD(driver, params)
    # chd_clean = clean_duplicate_ch("idChamp", chd_scrap, ch_base)
    # ret["champD"] = api_request(
    #     "post", params["urlApi"]+"/champ/create", chd_clean)

    driver.close()

    return ret
Пример #11
0
def create_TC(params):
    ret = {}

    driver = run_chrome()

    url = "/carreras.php?evento=calendario"
    driver.get(params["urlBase"] + url)

    time.sleep(5)
    e_scrap = get_events(driver, params)
    c_base = api_request("get", params["urlApi"] + "/circuit/ids/tc")
    c_clean = clean_duplicate("idCircuit", e_scrap[0], c_base)
    ret["circuits"] = api_request("post", params["urlApi"] + "/circuit/create",
                                  c_clean)

    time.sleep(5)
    e_base = api_request(
        "get", params["urlApi"] + "/event/ids/" + params["catId"] + "/" +
        params["year"])
    e_clean = clean_duplicate("idEvent", e_scrap[1], e_base)
    ret["events"] = api_request("post", params["urlApi"] + "/event/create",
                                e_clean)

    url = "/equipos.php?accion=pilotos"
    driver.get(params["urlBase"] + url)

    d_scrap = get_drivers(driver, params)

    url = "/estadisticas.php?accion=posiciones"
    driver.get(params["urlBase"] + url)

    time.sleep(5)
    chd_scrap = get_champD(driver, d_scrap[0], params)
    # ret["champD"] = chd_scrap
    d_base = api_request(
        "get", params["urlApi"] + "/driver/ids/" + params["catId"] + "/" +
        params["year"])
    d_clean = clean_duplicate("idPlayer", chd_scrap[0], d_base)

    time.sleep(2)
    t_base = api_request(
        "get", params["urlApi"] + "/team/ids/" + params["catId"] + "/" +
        params["year"])
    t_clean = clean_duplicate("idTeam", d_scrap[1], t_base)
    # ret["teams"] = api_request(
    #     "post", params["urlApi"] + "/team/create", t_clean)
    ret["teams"] = api_request("put", params["urlApi"] + "/team/update/0",
                               t_clean)

    time.sleep(5)
    # ret["drivers"] = api_request(
    #     "post", params["urlApi"] + "/driver/create", d_clean)
    ret["drivers"] = api_request("put", params["urlApi"] + "/driver/update/0",
                                 d_clean)

    time.sleep(5)
    ch_base = api_request(
        "get", params["urlApi"] + "/champ/ids/" + params["catId"] + "/" +
        params["year"])
    chd_clean = clean_duplicate_ch("idChamp", chd_scrap[1], ch_base)
    ret["champD"] = api_request("post", params["urlApi"] + "/champ/create",
                                chd_clean)

    if ("T" in params["chTypes"]):
        time.sleep(5)
        cht_scrap = get_champT(driver, d_scrap[1], params)
        # ret["champT"] = cht_scrap
        t_base = api_request(
            "get", params["urlApi"] + "/team/ids/" + params["catId"] + "/" +
            params["year"])
        t_clean = clean_duplicate("idTeam", cht_scrap[0], t_base)
        # ret["teamsT"] = api_request(
        #     "post", params["urlApi"] + "/team/create", t_clean)
        ret["teams"] = api_request("put", params["urlApi"] + "/team/update/0",
                                   t_clean)

        time.sleep(3)
        cht_clean = clean_duplicate_ch("idChamp", cht_scrap[1], ch_base)
        ret["champT"] = api_request("post", params["urlApi"] + "/champ/create",
                                    cht_clean)

    if ("C" in params["chTypes"]):
        time.sleep(5)
        chc_scrap = get_champC(driver, params)
        # ret["champC"] = chc_scrap
        t_clean = clean_duplicate("idTeam", chc_scrap[0], t_base)
        # ret["teamsC"] = api_request(
        #     "post", params["urlApi"] + "/team/create", t_clean)
        ret["teams"] = api_request("put", params["urlApi"] + "/team/update/0",
                                   t_clean)

        time.sleep(5)
        chc_clean = clean_duplicate_ch("idChamp", chc_scrap[1], ch_base)
        ret["champC"] = api_request("post", params["urlApi"] + "/champ/create",
                                    chc_clean)

    driver.close()

    return ret
Пример #12
0
def update_TC(params):
    ret = {}

    # CHAMPIONSHIPS
    driver = run_chrome()

    url = "/equipos.php?accion=pilotos"
    driver.get(params["urlBase"] + url)

    d_scrap = get_drivers(driver, params)

    if ("D" in params["chTypes"]):
        url = "/estadisticas.php?accion=posiciones"
        driver.get(params["urlBase"] + url)

        time.sleep(3)

        chd_base = api_request(
            "get", params["urlApi"] + "/champ/cat/" + params["catId"] + "/" +
            params["year"] + "/D")

        time.sleep(3)
        if (chd_base):
            champId = chd_base["_id"]
            sumPoints = chd_base.get("sumPoints", 0)
            chd_scrap = get_champD(driver, d_scrap[0], params)
            if (len(chd_scrap[1]) > 0
                    and chd_scrap[1].get("sumPoints", 0) > sumPoints):

                ret["teams"] = api_request("put",
                                           params["urlApi"] + "/team/update/0",
                                           d_scrap[1])

                time.sleep(3)
                ret["drivers"] = api_request(
                    "put", params["urlApi"] + "/driver/update/0", chd_scrap[0])

                time.sleep(3)
                ret["champD"] = api_request(
                    "put", params["urlApi"] + "/champ/update/" + champId,
                    chd_scrap[1])

    if ("T" in params["chTypes"]):
        cht_base = api_request(
            "get", params["urlApi"] + "/champ/cat/" + params["catId"] + "/" +
            params["year"] + "/T")

        if (cht_base):
            champId = cht_base["_id"]
            sumPoints = cht_base.get("sumPoints", 0)
            cht_scrap = get_champT(driver, d_scrap[1], params)
            if (len(cht_scrap[1]) > 0
                    and cht_scrap[1].get("sumPoints", 0) > sumPoints):

                ret["teams"] = api_request("put",
                                           params["urlApi"] + "/team/update/0",
                                           cht_scrap[0])

                time.sleep(3)
                ret["champD"] = api_request(
                    "put", params["urlApi"] + "/champ/update/" + champId,
                    cht_scrap[1])

    if ("C" in params["chTypes"]):
        chc_base = api_request(
            "get", params["urlApi"] + "/champ/cat/" + params["catId"] + "/" +
            params["year"] + "/C")

        if (chc_base):
            champId = chc_base["_id"]
            sumPoints = chc_base.get("sumPoints", 0)
            chc_scrap = get_champC(driver, params)
            if (len(chc_scrap[1]) > 0
                    and chc_scrap[1].get("sumPoints", 0) > sumPoints):

                ret["teams"] = api_request("put",
                                           params["urlApi"] + "/team/update/0",
                                           chc_scrap[0])

                time.sleep(3)
                ret["champD"] = api_request(
                    "put", params["urlApi"] + "/champ/update/" + champId,
                    chc_scrap[1])

    # EVENTS AND CIRCUITS
    if (params["updType"] == "events" or params["updType"] == "all"):
        time.sleep(3)
        e_base = api_request(
            "get", params["urlApi"] + "/event/cat/" + params["catId"] + "/" +
            params["year"])

        url = "/carreras.php?evento=calendario"
        driver.get(params["urlBase"] + url)

        e_scrap = get_events(driver, params)

        ret["events"] = e_base

        time.sleep(3)
        c_base = api_request("get", params["urlApi"] + "/circuit/ids/tc")
        c_clean = clean_duplicate("idCircuit", e_scrap[0], c_base)
        ret["circuits"] = api_request("post",
                                      params["urlApi"] + "/circuit/create",
                                      c_clean)

        compared = compareEvents(e_base, e_scrap[1])
        ret["compared"] = compared

        if (len(compared["news"]) > 0):
            time.sleep(5)
            ret["newEvents"] = api_request("post",
                                           params["urlApi"] + "/event/create",
                                           compared["news"])

        upds = compared["updated"]
        clds = compared["cancelled"]
        items = []
        for it in range(0, len(upds)):
            time.sleep(2)
            items.append(
                api_request(
                    "put",
                    params["urlApi"] + "/event/update/" + upds[it]["id"],
                    upds[it]["new"]))
        for it in range(0, len(clds)):
            time.sleep(2)
            items.append(
                api_request(
                    "put",
                    params["urlApi"] + "/event/update/" + clds[it]["id"],
                    clds[it]["new"]))
        ret["updEvents"] = items

    driver.close()

    return ret
Пример #13
0
def run_script_MSS(params):
    ret = {}

    # CHAMPIONSHIPS
    driver = run_chrome()

    if ("D" in params["chTypes"]):
        res = api_request(
            "get", params["urlApi"] + "/champ/cat/" + params["catId"] + "/" +
            params["year"] + "/D")

        url = "/series/" + params["catOrigen"] + \
            "/season/" + params["year"] + ""
        driver.get(params["urlBase"] + url)

        if (res):
            champId = res["_id"]
            sumPoints = res.get("sumPoints", 0)
            data = get_champD(driver, params)
            if (len(data) > 0 and data.get("sumPoints", 0) > sumPoints):
                ret["champD"] = api_request(
                    "put", params["urlApi"] + "/champ/update/" + champId, data)

    if ("C" in params["chTypes"]):
        time.sleep(5)
        res = api_request(
            "get", params["urlApi"] + "/champ/cat/" + params["catId"] + "/" +
            params["year"] + "/C")

        if (res):
            champId = res["_id"]
            sumPoints = res.get("sumPoints", 0)
            data = get_champC(driver, params)
            if (len(data) > 0 and data.get("sumPoints", 0) > sumPoints):
                ret["champT"] = api_request(
                    "put", params["urlApi"] + "/champ/update/" + champId, data)

    if ("T" in params["chTypes"]):
        time.sleep(5)
        res = api_request(
            "get", params["urlApi"] + "/champ/cat/" + params["catId"] + "/" +
            params["year"] + "/T")

        if (res):
            champId = res["_id"]
            sumPoints = res.get("sumPoints", 0)
            data = get_champT(driver, params)
            if (len(data) > 0 and data.get("sumPoints", 0) > sumPoints):
                ret["champT"] = api_request(
                    "put", params["urlApi"] + "/champ/update/" + champId, data)

    # EVENTS AND CIRCUITS
    if (params["updType"] == "events" or params["updType"] == "all"):
        time.sleep(5)
        res = api_request(
            "get", params["urlApi"] + "/event/cat/" + params["catId"] + "/" +
            params["year"])

        events = get_events(driver, params)
        ret["events"] = res

        circuits = run_script_circuits(driver, params, events)

        compared = compareEvents(res, events, True)
        ret["compared"] = compared

        ret["circuits"] = api_request("post",
                                      params["urlApi"] + "/circuit/update/0",
                                      circuits)

        if (len(compared["news"]) > 0):
            time.sleep(5)
            ret["newEvents"] = api_request("post",
                                           params["urlApi"] + "/event/create",
                                           compared["news"])

        upds = compared["updated"]
        clds = compared["cancelled"]
        items = []
        for it in range(0, len(upds)):
            time.sleep(2)
            items.append(
                api_request(
                    "put",
                    params["urlApi"] + "/event/update/" + upds[it]["id"],
                    upds[it]["new"]))
        for it in range(0, len(clds)):
            time.sleep(2)
            items.append(
                api_request(
                    "put",
                    params["urlApi"] + "/event/update/" + clds[it]["id"],
                    clds[it]["new"]))
        ret["updEvents"] = items

    # DRIVERS AND TEAMS
    if (params["updType"] == "all"):
        time.sleep(5)
        data = get_drivers(driver, params)

        ret["drivers"] = api_request("put",
                                     params["urlApi"] + "/driver/update/0",
                                     data)

        data = get_teams(driver, params)
        if (len(data) > 0):
            ret["teams"] = api_request("put",
                                       params["urlApi"] + "/team/update/0",
                                       data)

    driver.close()

    return ret
Пример #14
0
def update_AUVO(params):
    ret = {}

    driver = run_chrome()

    # CHAMPIONSHIPS

    # EVENTS AND CIRCUITS
    if (params["updType"] == "events" or params["updType"] == "all"):
        time.sleep(3)
        e_base = api_request(
            "get", params["urlApi"] + "/event/cat/" + params["catId"] + "/" +
            params["year"])

        url = "/calendario"
        driver.get(params["urlBase"] + url)

        e_scrap = get_events(driver, params)

        ret["events"] = e_base

        time.sleep(3)
        c_base = api_request("get", params["urlApi"] + "/circuit/ids/auvo")
        c_clean = clean_duplicate("idCircuit", e_scrap[0], c_base)
        ret["circuits"] = api_request("post",
                                      params["urlApi"] + "/circuit/create",
                                      c_clean)

        compared = compareEvents(e_base, e_scrap[1])
        ret["compared"] = compared

        if (len(compared["news"]) > 0):
            time.sleep(5)
            ret["newEvents"] = api_request("post",
                                           params["urlApi"] + "/event/create",
                                           compared["news"])

        upds = compared["updated"]
        clds = compared["cancelled"]
        items = []
        for it in range(0, len(upds)):
            time.sleep(2)
            items.append(
                api_request(
                    "put",
                    params["urlApi"] + "/event/update/" + upds[it]["id"],
                    upds[it]["new"]))
        for it in range(0, len(clds)):
            time.sleep(2)
            items.append(
                api_request(
                    "put",
                    params["urlApi"] + "/event/update/" + clds[it]["id"],
                    clds[it]["new"]))
        ret["updEvents"] = items

    # DRIVERS AND TEAMS
    if (params["updType"] == "drivers" or params["updType"] == "all"):
        time.sleep(5)
        url = "/" + params["catOrigen"] + "/pilotos.html"
        driver.get(params["urlBase"] + url)

        d_scrap = get_drivers(driver, params)
        t_scrap = get_teams(d_scrap, params)

        ret["teams"] = api_request("put", params["urlApi"] + "/team/update/0",
                                   t_scrap)

        time.sleep(5)
        ret["drivers"] = api_request("put",
                                     params["urlApi"] + "/driver/update/0",
                                     d_scrap)

    driver.close()

    return ret