Ejemplo n.º 1
0
    def get_entry_url(self):
        """
        Get url to enter game.

        :returns: `str` url.
        """
        if self._name is None:
            raise NotImplementedError(
                'Need set `_name` or override this function.'
            )

        return utils.build_url('game/{}'.format(self._name))
Ejemplo n.º 2
0
    def get_action_url(self, url_part):
        """
        Get action url from page by part of url.

        :param url_part: part of url.
        :returns: `str` url or `None`.
        """
        try:
            xpath = '//a[contains(@href, "{}")]/@href'.format(url_part)
            return utils.build_url(self._page.xpath(xpath)[0])
        except IndexError:
            return None
Ejemplo n.º 3
0
    def entry(self):
        """
        Enter to game.

        :returns: `str` url for entry to game.
        """
        page = super(Towers, self).entry()

        self._capital = utils.remove_spaces(page.xpath('//h1//text()')[0])

        tower_link = page.xpath('//a[contains(@href, "nearLocation")]')[0]
        self._tower = utils.remove_spaces(tower_link.xpath('span/text()')[0])
        self._location = self._tower

        return self.move(utils.build_url(tower_link.xpath('@href')[0]))
Ejemplo n.º 4
0
    def get_move_forward_urls(self):
        """
        Get backward towers url from page.

        :returns: `list` of `str` url.
        """
        urls = self._page.xpath('//a[contains(@href, "location")]')

        if '-n' in urls[-1].xpath('img/@src')[0]:
            forward = '-n'
        elif '-s' in urls[-1].xpath('img/@src')[0]:
            forward = '-s'
        else:
            return []

        urls = filter(lambda x: forward in x.xpath('img/@src')[0], urls)
        return map(lambda x: utils.build_url(x.xpath('@href')[0]), urls)