Exemplo n.º 1
0
    def __get_individual_transfer_info(self, transfer):
        """ Get the information for an individual transfer on club's transfers page. """
        try:
            amount = self.get_value_from_string(
                transfer.find('b').text)  # Get transfer amount
        except:
            print(
                f"Could not get transfer info for transfer {transfer.find('b').text}"
            )

        td = transfer.find('td')
        player_name = td.text  # that's player, not manager
        player_id = util.get_id_from_href(td.find_all('a')[1].get('href'))

        text_info = str(td)
        date = self.__get_date_from_transfer(text_info)  # Get date of transfer
        other_club = self.__get_other_club_from_transfer(
            text_info)  # Other club involved in transfer

        # Return dict containing all info
        return {
            'amount': amount,
            'date': date,
            'other_club': other_club,
            'player_id': player_id,
            'player_name': player_name
        }
Exemplo n.º 2
0
    def request_listed_players(self, position):
        request = self.session.request(
            "POST",
            suburl='lista_transferuri.php',
            data={
                'varsta': 0,  # Age
                'pozitie': position,
                'A1': 10,  # Skill 1
                'A2': 10,  # Skill 2
                'A3': 10,  # Skill 3
                'AMB': 1,  # Ambition
                'INT': 1,  # Intelligence
                'REZ': 1,  # Stamina
                'AGR':
                5,  # Aggression (highest considered worst, hence redboy has default set to 5)
                'VUL':
                5,  # Vulnerability (highest considered worst, hence redboy has default set to 5)
            })

        soup = make_soup(request)
        player_ids = [
            util.get_id_from_href(i.get('action'))
            for i in soup.find_all('form')
        ]
        return player_ids
Exemplo n.º 3
0
    def __search_for_id(search, soup, by_manager=False):
        """ Given the soup from a users_search_query, 
        Returns the club_id if found, else False. """

        # Set index to 1 (first instance of club name), and iterate
        # through remaining search results if necessesary until finds match
        table_rows = soup.find_all('table')[2].find_all('tr')
        index = 1

        get_href = lambda index: table_rows[index].find_all('td')[2].find(
            'a').get('href')
        if by_manager:
            get_result = lambda index: table_rows[index].find_all('td')[
                0].find('b').text
        else:
            get_result = lambda index: table_rows[index].find_all('td')[
                2].find('a').text

        while True:
            try:
                search_result = get_result(index)
            except:
                # print(f"\nUnable to find team: {search}")
                return False
                # raise Exception(f"Unable to find team: {club}")

            # Verifies that (team_name == club) where club is what you're searching for
            if search_result.lower() == search:
                href = get_href(index)
                return util.get_id_from_href(href)
            else:
                pass
                # print(f"{search_result} is not {search}")
            index += 1
        return False
Exemplo n.º 4
0
 def league(self):
     """ Returns the current league of a club. """
     i = 2 if self.status in ('bot', 'user', 'corrupt') else 4
     # Get link that goes to club's current league
     link = self.soup_dict['club_info_links'][i]
     # Get league_id from this link
     league_id = util.get_id_from_href(link.get('href'))
     return league_id
Exemplo n.º 5
0
 def get_manager(tr):
     """
     Get the information about a single manager based on the row.
     """
     # Manager is active. Get their information.
     manager = tr.find('b').text
     club_link = tr.find('a', href=re.compile(r"vizualizare_club.php\?"))
     club_name = club_link.text
     club_id = util.get_id_from_href(club_link.get('href'))
     
     return {'club_id': club_id, 'club': club_name, 'manager': manager}
Exemplo n.º 6
0
    def __get_player_ids_from_squad_table(cls, table):
        """ Returns list of player_ids from a given table in squad table soup.
        e.g. returns all goalkeepers, or returns all defenders """

        """ Grabs the player profile link for each player on the squad page,
        NOTE that there are two different ways of viewing a squad. When you
        look at your own club, you have access to more information. However
        you can only do this for your own club. This function makes use of the 
        more restricted view, which is how you look at others' clubs. """
        player_hrefs = [n.find('td').find_all('a')[-1].get('href') for n in table.find_all('tr')[1:]]

        # Grab and return id from each href in the above list
        return [util.get_id_from_href(x) for x in player_hrefs]
Exemplo n.º 7
0
 def __get_team_id_from_team_search(soup, club):
     index = 1
     while True:
         try:
             a_tag = soup.find_all('table')[2].find_all(
                 'tr')[index].find_all('td')[2].find('a')
         except:
             raise Exception(f"Unable to find team: {club}")
         team_name = a_tag.text
         if team_name == club:
             href = a_tag.get('href')
             return util.get_id_from_href(href)
         index += 1
Exemplo n.º 8
0
 def conduct_search(data):
     """ Conduct an individual search on Best11 for transfer listed players. """
     request = req_post(self.sesh, subpage, data=data)
     soup = make_soup(request)
     # Forms containing player forms which contains their links
     forms = soup.find_all('table')[1].find_all('form')
     # Get player_ids from form links
     ids = [
         int(util.get_id_from_href(i))
         for i in [j.get('action') for j in forms]
     ]
     # Add ids to main list
     return ids
Exemplo n.º 9
0
    def __get_wealthiest_clubs(self):
        """
        Returns a dictionary of the richest 100 Best11 clubs.
        r-type: dict
        r-format {wealth_rank: club_id}; {int: int}
        """
        
        request = self.session.request(
            "GET",
            suburl = "wealth.php"
        )

        soup = make_soup(request)
        table_rows = soup.find('table').find_all('tr')[1:]

        table_entries = [{int(i.find_all('td')[0].text): util.get_id_from_href(i.find_all('td')[2].find('a').get('href'))} for i in table_rows]
        wealth_100 = util.flat_list_of_dicts(table_entries)
        return wealth_100
Exemplo n.º 10
0
        def is_active(tr):
            """ Returns the club_id of the club if they are active, else False.
            rtype: int """
            # Get last logged in
            last_logged_in = tr.find_all('td')[3].text

            # Bypass weird Best11 error wherby the year is 0
            # NOTE These managers are no longer active regardless.
            year = int(last_logged_in.split('-')[0])
            if year == 0:
                return False

            # Convert to pendulum.datetime
            last_logged_in = pendulum.parse(last_logged_in, tz=tz.server)
            if last_logged_in < target_datetime:
                # Manager is inactive
                return False

            # Manager is active
            href = tr.find_all('td')[2].find('a').get('href')
            club_id = util.get_id_from_href(href)
            return club_id
Exemplo n.º 11
0
    def club_id_from_manager(self, manager):
        """
        Given a manager's name, returns their club's id
        r-type: int

        Parameters:
            - manager (str) - case doesn't matter
        """

        manager = manager.lower() # Ensure lowercase club parameter
        request = self.session.request(
            "POST",
            suburl="useri.php?",
            params = {'pag': 'cauta'},
            data = {'cautare': 2, 'manager': manager}
        )
        soup = make_soup(request)
        table_rows = soup.find_all('table')[2].find_all('tr')[1:]

        get_href = lambda index: table_rows[index].find_all('td')[2].find('a').get('href')
        get_result = lambda index: table_rows[index].find_all('td')[0].find('b').text

        index = 0
        while index < len(table_rows):
            try:
                search_result = get_result(index)
            except:
                return False 

            # Verifies that (team_name == manager) where manager is what you're searching for
            if search_result.lower() == manager:
                href = get_href(index)
                club_id = util.get_id_from_href(href)
                return club_id
            else:
                pass
            index += 1
        return False
Exemplo n.º 12
0
 def club_id(self, table_index=''):
     """ Get CLUB_ID from player profile instance """
     href = self.tables[table_index].find_all('td')[2].find('a').get('href')
     return util.get_id_from_href(href)