예제 #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
파일: tr.py 프로젝트: pah-dev/scraper-rctrl
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
예제 #3
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
예제 #4
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
예제 #5
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