Example #1
0
def enter_junior_roster(id_team, auth):
    """ Recorremos las páginas de canteras
    Devolvemos un array con los ids de los jugadores que
      conforman la cantera

  Keyword arguments:
    id_team -- Id del equipo al que se va a acceder a su cantera
    auth -- Cadena de autenticacion a la web.
    db -- Objeto de conexion a la BD.
  """
    session = login(auth)

    jr_url = "http://es.ibasketmanager.com/plantilla.php?" + \
      "juveniles=1&id_equipo=" + str(id_team)

    r = session.get(jr_url)
    load_status = 0
    while load_status != 200:
        load_status = r.status_code

    juniors = []
    soup = BeautifulSoup(r.content, "html.parser")
    juniors_str = soup.find_all("table", {"id": "pagetabla"})
    juniors_str = BeautifulSoup(str(juniors_str), "html.parser").find_all(
        "td", {"class": "jugador"})
    if juniors_str is not None:
        for junior_str in juniors_str:
            # print(junior_str.find('a')['href'][junior_str.find(
            #    'a')['href'].find('=')+1:])
            # Sustituir por split()[1]
            juniors.append(
                junior_str.find("a")["href"]
                [junior_str.find("a")["href"].find("=") + 1:])

    return juniors
Example #2
0
def enter_senior_roster(id_team, auth):
    """ Recorremos las páginas de plantillas
    Devolvemos un array con los ids de los jugadores
      que conforman la plantilla

  Keyword arguments:
    id_team -- Id del equipo al que se va a acceder a su plantilla
    auth -- Cadena de autenticacion a la web.
    db -- Objeto de conexion a la BD.
  """
    session = login(auth)

    senior_roster_url = "http://es.ibasketmanager.com/plantilla.php?id_equipo="\
      + str(id_team)

    r = session.get(senior_roster_url)
    load_status = 0
    while load_status != 200:
        load_status = r.status_code

    seniors = []
    soup = BeautifulSoup(r.content, 'html.parser')
    seniors_str = soup.find_all('table', {"id": "pagetabla"})
    seniors_str = BeautifulSoup(str(seniors_str), 'html.parser').find_all(
        "td", {"class": "jugador"})
    if seniors_str is not None:
        for senior_str in seniors_str:
            # print(senior_str.find('a')['href'][senior_str.find(
            #    'a')['href'].find('=')+1:])
            seniors.append(
                senior_str.find("a")["href"]
                [senior_str.find("a")["href"].find("=") + 1:])

    return seniors
def analyze_team_page(auth, db, id_team):
    """ Analizamos la pagina del equipo

  Keyword arguments:
    auth -- Cadena de autenticacion a la web.
    db -- Objeto de conexion a la BD.
  """
    session = login(auth)

    url = "http://es.ibasketmanager.com/equipo.php?id=" + id_team
    r = session.get(url)
    load_status = 0
    while load_status != 200:
        load_status = r.status_code

    print(show("profile") + " > Analizando perfil del equipo")

    soup = BeautifulSoup(r.content, "html.parser")

    trs2 = soup.find_all("tr", {"class": "tipo2"})

    id_user = trs2[0].find("a")["href"].split("=")[1]
    streak = trs2[2].find_all("td")[1].text
    club_seats = trs2[3].find_all("td")[1].text.replace(".", "").strip()
    ranking = trs2[4].find_all("td")[1].text.replace("Ranking", "").strip()

    trs1 = soup.find_all("tr", {"class": "tipo1"})
    fans = trs1[3].find_all("td")[1].text.replace(".", "").strip()

    return [id_user, club_seats, fans, ranking, streak]
def analyze_init(auth, db):
    """ Analizamos la pagina de inicio

  Keyword arguments:
    auth -- Cadena de autenticacion a la web.
    db -- Objeto de conexion a la BD.
  """
    session = login(auth)

    url = "http://es.ibasketmanager.com/inicio.php"
    r = session.get(url)
    load_status = 0
    while load_status != 200:
        load_status = r.status_code

    print(show("profile") + " > Analizando perfil inicial")

    soup = BeautifulSoup(r.content, "html.parser")
    a = soup.find_all("a", {"class": "color_skin"})
    camisetas = soup.find_all("div", {"class": "camiseta"}, style=True)
    color_prim = camisetas[0]["style"].split(":")[1].strip()
    color_sec = camisetas[1]["style"].split(":")[1].strip()
    # print(a)
    username = a[0].text
    id_team = a[2]["href"].split("=")[1].strip()
    team_name = a[2].text.strip()
    money = a[3].text.replace('€', '').replace('.', '').strip()

    return [id_team, username, team_name, money, color_prim, color_sec]
Example #5
0
def analyze_market_page(auth, params, db):
    """ Accede a la página del mercado obtenida de los parametros

  Keyword arguments:
    auth -- Cadena de autenticacion a la web.
    params -- Parametros para construir la url del mercado.
    db -- Objeto de conexion a la BD.
  """

    session = login(auth)

    market_url = "http://es.ibasketmanager.com/mercado.php"
    market_url = market_url + "?juvenil=" + str(params["juvenil"])
    market_url = market_url + "&tiempos=" + str(params["tiempos"])
    market_url = market_url + "&posiciones=" + str(params["posiciones"])
    market_url = market_url + "&calidad=" + str(params["calidad"])
    market_url = market_url + "&edad" + str(params["edad"])
    market_url = market_url + "&cdirecta=" + str(params["cdirecta"])
    print(show("market") + ">{ " + market_url + " }")

    r = session.get(market_url)
    load_status = 0
    while load_status != 200:
        load_status = r.status_code
    auctions = get_auctions(r.content)

    for v_auction in auctions:
        # print("\t{}".format(auction))
        # Realizamos un analisis profundo de cada jugador
        player = player_page.get_player_data(v_auction.id_player, auth)
        # Esto es una tupla
        similars = player_page.get_similar_data(v_auction.id_player, auth)
        # print(similars)
        # Insertamos la subasta
        db.market.insert_one(v_auction.to_db_collection())

        player_page.insert_player(player, v_auction.id_player, db)
        player_page.insert_similars(similars, db)
Example #6
0
def get_player_data(id_player, auth):
    """ Obtenemos los datos del jugador pasado por parametros

  Keyword arguments:
    id_player -- Id del jugador con el que cargamos su página
    auth -- Cadena de autenticacion a la web.
  """

    session = login(auth)
    # http://es.ibasketmanager.com/jugador.php?id_jugador=7192302
    # http://es.ibasketmanager.com/jugador.php?id_jugador=7856412
    # id_player = 7856412
    player_url = "http://es.ibasketmanager.com/" + \
      "jugador.php?id_jugador=" + str(id_player)
    # print(show("player") + " >{ " + player_url + " }")
    r = session.get(player_url)
    load_status = 0
    while load_status != 200:
        load_status = r.status_code

    v_player = analyze_player_page(id_player, r.content)

    return v_player
Example #7
0
def enter_team(auth, db, own_team_id):
    """ Recorremos las páginas de plantilla y cantera del equipo
    y registra los atributos de los jugadores para
    la posterior comprobación de la progresión

  Keyword arguments:
    auth -- Cadena de autenticacion a la web.
    db -- Objeto de conexion a la BD.
    own_team_id -- Id del equipo
  """
    session = login(auth)

    # Analizo el progreso del equipo
    print(
        show("team_info") + "   > Analizando Equipo propio: " +
        str(own_team_id))

    # Seniors
    print(show("roster") + "   -> Plantilla: " + str(own_team_id))
    players_ids = roster_page.enter_senior_roster(own_team_id, auth)
    for player_id in players_ids:
        player = player_page.get_player_data(player_id, auth)

        player_page.insert_player(player, player_id, db)

        db.players_progression.insert_one(player[1].to_db_collection())

    # Juniors
    print(show("juniors") + "   -> Cantera:   " + str(own_team_id))
    juniors_ids = roster_page.enter_junior_roster(own_team_id, auth)
    for junior_id in juniors_ids:
        junior = player_page.get_player_data(junior_id, auth)

        player_page.insert_player(junior, junior_id, db)

        db.players_progression.insert_one(player[1].to_db_collection())