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
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
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
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
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