How to use the fpl.utils.logged_in function in fpl

To help you get started, we’ve selected a few fpl examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github amosbastian / fpl / tests / test_utils.py View on Github external
async def test_logged_in(self, loop, fpl):
        await fpl.login()
        assert logged_in(fpl.session)
github amosbastian / fpl / fpl / fpl.py View on Github external
async def get_h2h_league(self, league_id, return_json=False):
        """Returns a `H2HLeague` object with the given `league_id`. Requires
        the user to have logged in using ``fpl.login()``.

        Information is taken from e.g.:
            https://fantasy.premierleague.com/api/leagues-h2h-matches/league/946125/

        :param league_id: A H2H league's ID.
        :type league_id: string or int
        :param return_json: (optional) Boolean. If ``True`` returns a ``dict``,
            if ``False`` returns a :class:`H2HLeague` object. Defaults to
            ``False``.
        :type return_json: bool
        :rtype: :class:`H2HLeague` or ``dict``
        """
        if not logged_in(self.session):
            raise Exception("User must be logged in.")

        url = API_URLS["league_h2h"].format(league_id)
        league = await fetch(self.session, url)

        if return_json:
            return league

        return H2HLeague(league, session=self.session)
github amosbastian / fpl / fpl / models / h2h_league.py View on Github external
async def get_fixtures(self, gameweek=None, page=1):
        """Returns a list of fixtures / results of the H2H league.

        Information is taken from e.g.:
            https://fantasy.premierleague.com/api/leagues-h2h-matches/league/946125/?page=1

        :param gameweek: (optional) The gameweek of the fixtures / results.
        :type gameweek: string or int
        :param page: (optional) The fixtures / results page.
        :type page: string or int
        :rtype: list
        """
        if not self._session:
            return []

        if not logged_in(self._session):
            raise Exception(
                "Not authorised to get H2H fixtures. Log in first.")

        url_query = f"event={gameweek}&" if gameweek else ""
        has_next = True
        results = []

        while has_next:
            fixtures = await fetch(
                self._session, API_URLS["league_h2h_fixtures"].format(
                    self.league["id"], url_query, page))
            results.extend(fixtures["results"])

            has_next = fixtures["has_next"]
            page += 1
github amosbastian / fpl / fpl / models / user.py View on Github external
async def get_chips(self):
        """Returns a logged in user's list of chips. Requires the user to have
        logged in using ``fpl.login()``.

        Information is taken from e.g.:
            https://fantasy.premierleague.com/api/my-team/91928/

        :rtype: list
        """
        if not logged_in(self._session):
            raise Exception("User must be logged in.")

        response = await fetch(
            self._session, API_URLS["user_team"].format(self.id))

        if response == {"details": "You cannot view this entry"}:
            raise ValueError("User ID does not match provided email address!")

        return response["chips"]