Beispiel #1
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]))
Beispiel #2
0
    def get_action_log(self):
        """
        Get last line from game log.

        :returns: `str` of log.
        """
        log = self._page.xpath(u'//div[contains(text(), "Ты")][1]//text()')
        return u'Location: {}\n{}'.format(
            self._location, utils.remove_spaces(''.join(log))
        )
Beispiel #3
0
    def move(self, url):
        """
        Do action (change location, attack or etc.) and save response.

        :param url: `str` url of action.
        :returns: `lxml.html` instance.
        """
        page = super(Towers, self).move(url)
        self._location = utils.remove_spaces(page.xpath('//h1/span/text()')[0])
        return page
Beispiel #4
0
    def get_move_capital_url(self):
        """
        Get capital url from page.

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

        condition = lambda x: (
            utils.remove_spaces(x.xpath('span/text()')[0]) == self._capital
        )

        try:
            return filter(condition, urls)[0]
        except IndexError:
            return None