Ejemplo n.º 1
0
    def get_techstaff(self,
                      slot,
                      first_name,
                      last_name,
                      salary=24000,
                      signon=50000,
                      level=10):
        """ Given the parameters for the form that you normally click to choose a coach,
        makes a post request using that same link, then follows up with a get request
        to confirm the coach. 
        NOTE: amounts are given as 50.000 C = 50000. """

        # Edge cases
        if any([not str(x).isdigit() for x in (slot, level, salary, signon)]):
            raise TypeError(
                "slot, level, salary and signon must all be numbers")

        data = {
            'slot': str(slot),
            'nivel': str(level),
            'prenume': first_name,
            'nume': last_name,
            'salariu': str(salary),
            'semnatura': str(signon),
        }
        # Make initial request using data, takes you to confirmation screen
        req_post(self.sesh, "confirma_antrenor.php", data=data)

        # Make simple follow-up get request to confirm coach selection
        # Equivalent of clicking "confirm"
        req_get(
            self.sesh,
            "antrenor_nou.php",
            headers={'referer': 'https://best11.org/confirma_antrenor.php'})
Ejemplo n.º 2
0
    def get_psychologist(self,
                         first_name,
                         last_name,
                         salary=19000,
                         signon=0,
                         level=4):
        """ As with get_techstaff, 
        Make post request to get coach and then make follow up get request
        for confirmation. """
        # Edge cases
        if any([not str(x).isdigit() for x in (level, salary, signon)]):
            raise TypeError("level, salary and signon must all be numbers")

        data = {
            'nivel': str(level),
            'prenume': first_name,
            'nume': last_name,
            'salariu': str(salary),
            'semnatura': str(signon)
        }

        # Make initial request using data, takes you to confirmation screen
        req_post(self.sesh, "confirma_psiholog.php", data=data)

        # Follow up request for confirmation
        req_get(
            self.sesh,
            "psiholog_nou.php",
            headers={'referer': 'https://best11.org/confirma_antrenor.php'})
Ejemplo n.º 3
0
    def send_forum(self, msg, forum):
        """ Post a message on a given forum. """
        if not msg:
            print("You didn't enter a message... Try again, sport. ")
            return
        
        ## Identify chosen forum if possible
        forum_id = None
        for forum_name, id in self.forum_ids.items():
            if forum in forum_name:
                forum = forum_name
                forum_id = str(id)
                break
        # Forum not found
        if not forum_id:
            print(f"Could not get forum_id from given forum name: {forum}")
            return

        ## Confirmation via User Input
        if not yn(f"Post message to forum {forum_name}?"):
            return

        ## Make the request
        req_post(
            self.sesh,
            self.suburl_forum_main,
            params={'pag': "postare_noua"},
            data={'categ': forum_id, 'mesaj': msg}
        )
Ejemplo n.º 4
0
 def __users_search_query(session, search_club_id_payload):
     """ Conducts a search query on the users page,
     Returns the resulting soup. """
     request = req_post(session,
                        'useri.php?',
                        params={"pag": "cauta"},
                        data=search_club_id_payload)
     return make_soup(request)
Ejemplo n.º 5
0
    def __get_active_managers(self):
        """ Returns a list of active managers.
        rtype: list """

        # Make post request via Community > Users > Search > Search by Manager
        request = req_post(
            self.sesh,
            "useri.php?",
            params={"pag": "cauta"},
            data={
                'cautare': 2,
                'manager': ''
            }  # Leave manager blank - shows all
        )
        # Get resulting soup
        soup = make_soup(request)

        # Grab the table containing table rows containing data for...
        # User, Action, Club, Last Login
        table = soup.find_all('table')[2]

        # Manager considered inactive if last_logged_in before target_datetime
        server_time = pendulum.now(tz=tz.server)
        target_datetime = server_time.subtract(days=7)

        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

        # Get all table rows in users search query soup
        table_rows = table.find_all('tr')[1:]

        # Run is_active() func for each manager
        active_managers = []
        while table_rows:
            # Add each manager to the list if they are active
            if n := (is_active(table_rows.pop())):
                active_managers.append(n)
Ejemplo n.º 6
0
 def __train_slot(self, slot):
     """ Makes a request to get the training points from
     ONE of the technical staff, given that staff member's slot
     e.g. the first coach would be 1 """
     # TODO does this have to be POST request? There is no data
     request = req_post(self.sesh,
                        "antrenor.php?",
                        params={
                            'pag': 'antrenament',
                            'slot': str(slot)
                        })
     return self.__tp_earnings(request, slot)
Ejemplo n.º 7
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
Ejemplo n.º 8
0
    def send_guestbook(self, msg, recipient=None, sender=None):
        """ 
        Post a message to the recipient's guestbook. 

        Guestbook is the only place that allows you to post
        as someone else, hence the optional sender parameter
        
        If no sender is given, the sender defaults to the user
        If no recipient is given, the recipient defaults to the user (not to the sender) 
        """

        if not msg:
            print("You didn't enter a message... Try again, sport. ")
            return

        ## Get Club object for sender
        if not sender:
            sender = self.user_club
        else:
            sender = self.get_club(sender)

        ## Get Club object for recipient
        if not recipient:
            recipient = self.user_club
        else:
            recipient = self.get_club(recipient)
        
        ## Confirmation via User Input
        if not yn(f"Sender: {sender.manager}\nRecipient: {recipient.manager}"):
            return

        ## Make the request
        req_post(
            self.sesh,
            self.suburl_guestbook,
            params={'pag': 'new'},
            data={'club': recipient.club_id, 'user': self.user_club.msg_id, 'mesaj': msg}
        )
Ejemplo n.º 9
0
    def send_msg(self, msg, subject, recipient=None):
        """ Send a message to yourself or another user.
        NOTE: The sender will always be the user - it cannot be changed """

        # Edge case: no message entered
        if not msg:
            print("You didn't enter a message... Try again, sport. ")
            return

        if not recipient:
            # No recipient given - recipient defaults to user
            recipient = self.user_club
        else:
            recipient = self.get_club(recipient)

        if not yn(f"Sender: {self.sesh.username}\nRecipient: {recipient.manager}"):
            return

        req_post(
            self.sesh,
            self.suburl_message,
            params={'catre': str(recipient.msg_id), 'pag': "confirmare"},
            data={'titlu': subject, 'mesaj': msg}
        )
Ejemplo n.º 10
0
    def send_lgepage(self, msg, league_id=None):
        """ Post a message on a league forum. """
        if not msg:
            print("You didn't enter a message... Try again, sport. ")
            return
        
        if not league_id:
            league_id = self.user_club.league
        league_id = str(league_id)
        if not league_id.isdigit():
            print("league_id must be a number!")
            return

        ## Confirmation via User Input
        if not yn(f"Post message to league {league_id}?"):
            return

        ## Make the request
        req_post(
            self.sesh,
            self.suburl_forum_league,
            params={'pag': "postare_noua"},
            data={'categ': str(league_id), 'mesaj': msg}
        )