Esempio n. 1
0
    def _parse_leaderboard_selectors(self, selector_table):
        """Parses the option selectors from the leaderboards to get their information.

        Parameters
        ----------
        selector_table: :class:`bs4.BeautifulSoup`

        Returns
        -------
        :class:`bool`
            Whether the selectors could be parsed or not.
        """
        world_select = selector_table.find("select", attrs={"name": "tournamentworld"})
        selected_world = world_select.find("option", {"selected": "selected"})
        if not selected_world:
            return False
        self.world = selected_world.text
        tournament_select = selector_table.find("select", attrs={"name": "tournamentcycle"})
        selected_tournament = tournament_select.find("option", {"selected": "selected"})
        tournament_text = selected_tournament.text
        start_date = None
        end_date = None
        cycle = int(selected_tournament["value"])
        if "current tournament" in tournament_text.lower():
            tournament_title = CURRENT_TOURNAMENT_PATTERN.sub(r"\g<1>", tournament_text)
        else:
            m = ARCHIVE_LIST_PATTERN.search(tournament_text)
            tournament_title = m.group(1).strip()
            start_date = parse_tibia_full_date(m.group(2))
            end_date = parse_tibia_full_date(m.group(3))
        self.tournament = ListedTournament(title=tournament_title, start_date=start_date, end_date=end_date,
                                           cycle=cycle)
        return True
Esempio n. 2
0
    def _parse_archive_list(self, archive_table):
        """Parses the archive list table.

        This table is only visible when viewing a tournament from the archive.

        Parameters
        ----------
        archive_table: :class:`bs4.Tag`
            The parsed element containing the table.
        """
        _, *options = archive_table.find_all("option")
        self.archived_tournaments = []
        for option in options:
            m = ARCHIVE_LIST_PATTERN.match(option.text)
            if not m:
                continue
            title = m.group(1).strip()
            start_date = parse_tibia_full_date(m.group(2))
            end_date = parse_tibia_full_date(m.group(3))
            value = int(option["value"])
            if title == self.title:
                self.cycle = value
            self.archived_tournaments.append(
                ListedTournament(title=title,
                                 start_date=start_date,
                                 end_date=end_date,
                                 cycle=value))
Esempio n. 3
0
    def _parse_worlds(self, world_rows, tournament=False):
        """Parse the world columns and adds the results to :py:attr:`worlds`.

        Parameters
        ----------
        world_rows: :class:`list` of :class:`bs4.Tag`
            A list containing the rows of each world.
        tournament: :class:`bool`
            Whether these are tournament worlds or not.
        """
        for world_row in world_rows:
            cols = world_row.find_all("td")
            name = cols[0].text.strip()
            status = "Online"
            online = parse_integer(cols[1].text.strip(), None)
            if online is None:
                online = 0
                status = "Offline"
            location = cols[2].text.replace("\u00a0", " ").strip()
            pvp = cols[3].text.strip()

            world = WorldEntry(name, location, pvp, online_count=online, status=status)
            # Check Battleye icon to get information
            battleye_icon = cols[4].find("span", attrs={"class": "HelperDivIndicator"})
            if battleye_icon is not None:
                m = battleye_regexp.search(battleye_icon["onmouseover"])
                if m:
                    world.battleye_date = parse_tibia_full_date(m.group(1))
                    world.battleye_type = BattlEyeType.PROTECTED if world.battleye_date else BattlEyeType.INITIALLY_PROTECTED
            additional_info = cols[5].text.strip()
            world._parse_additional_info(additional_info, tournament)
            self.worlds.append(world)
Esempio n. 4
0
    def _parse_battleye_status(self, battleye_string):
        """Parse the BattlEye string and applies the results.

        Parameters
        ----------
        battleye_string: :class:`str`
            String containing the world's Battleye Status.
        """
        m = battleye_regexp.search(battleye_string)
        if m:
            self.battleye_date = parse_tibia_full_date(m.group(1))
            self.battleye_type = BattlEyeType.PROTECTED if self.battleye_date else BattlEyeType.INITIALLY_PROTECTED
        else:
            self.battleye_date = None
            self.battleye_type = BattlEyeType.UNPROTECTED
Esempio n. 5
0
    def _parse_battleye_status(self, battleye_string):
        """Parses the BattlEye string and applies the results.

        Parameters
        ----------
        battleye_string: :class:`str`
            String containing the world's Battleye Status.
        """
        m = battleye_regexp.search(battleye_string)
        if m:
            self.battleye_protected = True
            self.battleye_date = parse_tibia_full_date(m.group(1))
        else:
            self.battleye_protected = False
            self.battleye_date = None
Esempio n. 6
0
    def _parse_worlds(self, world_rows):
        """Parses the world columns and adds the results to :py:attr:`worlds`.

        Parameters
        ----------
        world_rows: :class:`list` of :class:`bs4.Tag`
            A list containing the rows of each world.
        """
        tournament = False
        for world_row in world_rows:
            cols = world_row.find_all("td")
            name = cols[0].text.strip()
            status = "Online"
            if len(cols) == 1 and name == "Tournament Worlds":
                tournament = True
                continue
            elif len(cols) == 1 and name == "Regular Worlds":
                tournament = False
                continue
            elif name == "World":
                continue
            try:
                online = parse_integer(cols[1].text.strip())
            except ValueError:
                online = 0
                status = "Offline"
            location = cols[2].text.replace("\u00a0", " ").strip()
            pvp = cols[3].text.strip()

            world = ListedWorld(name,
                                location,
                                pvp,
                                online_count=online,
                                status=status)
            # Check Battleye icon to get information
            battleye_icon = cols[4].find("span",
                                         attrs={"class": "HelperDivIndicator"})
            if battleye_icon is not None:
                world.battleye_protected = True
                m = battleye_regexp.search(battleye_icon["onmouseover"])
                if m:
                    world.battleye_date = parse_tibia_full_date(m.group(1))

            additional_info = cols[5].text.strip()
            world._parse_additional_info(additional_info, tournament)
            self.worlds.append(world)
Esempio n. 7
0
 def test_parse_tibia_date_full(self):
     date = utils.parse_tibia_full_date(TIBIA_FULL_DATE)
     self.assertIsInstance(date, datetime.date)
     self.assertEqual(date.month, 7)
     self.assertEqual(date.day, 23)
     self.assertEqual(date.year, 2015)