From 96077319d5fea4b2d7bf90e925d6ad82dd89bad1 Mon Sep 17 00:00:00 2001 From: johnmadden86 Date: Tue, 22 Oct 2019 13:41:35 +0100 Subject: [PATCH] import async_property library --- fpl/fpl.py | 4 ++-- fpl/models/user.py | 25 ++++++++++++++++++------- setup.py | 4 +++- 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/fpl/fpl.py b/fpl/fpl.py index 7d5a0cf..259b980 100644 --- a/fpl/fpl.py +++ b/fpl/fpl.py @@ -250,8 +250,8 @@ async def get_player(self, player_id, players=None, gameweek=None, include_summa player["id"], return_json=True) player.update(player_summary) - player["image_url"] = f'https://platform-static-files.s3.amazonaws.com' \ - f'/premierleague/photos/players/110x140/p{player["code"]}.png' + player["image_url"] = (f'https://platform-static-files.s3.amazonaws.com' + f'/premierleague/photos/players/110x140/p{player["code"]}.png') if gameweek: player["live_score"] = gameweek.elements[player_id]["stats"]["total_points"] diff --git a/fpl/models/user.py b/fpl/models/user.py index 108a6dc..42c32a6 100644 --- a/fpl/models/user.py +++ b/fpl/models/user.py @@ -1,6 +1,8 @@ import asyncio import json +from async_property import async_cached_property + from ..constants import API_URLS from ..utils import fetch, logged_in, post, get_headers @@ -120,7 +122,11 @@ def _get_first_xi(picks, players): def _get_subs(picks, players): - return [players[pick["element"]].id for pick in picks if pick["position"] > 11] + return [players[pick["element"]].id + for pick in picks + if pick["position"] > 11 + and + not players[pick["element"]].did_not_play] class User: @@ -144,7 +150,7 @@ def __init__(self, user_information, session): for k, v in user_information.items(): setattr(self, k, v) - @property + @async_cached_property async def history(self): history = await fetch(self._session, API_URLS["user_history"].format(getattr(self, "id"))) return history @@ -198,15 +204,12 @@ async def get_chips_history(self, gameweek=None): return chips - @property + @async_cached_property async def picks(self): """Returns a dict containing the user's picks each gameweek. - Key is the gameweek number, value contains picks of the gameweek. - Information is taken from e.g.: https://fantasy.premierleague.com/api/entry/91928/event/1/picks/ - :rtype: dict """ @@ -382,8 +385,16 @@ async def get_team(self): return response["picks"] - @property + @async_cached_property async def transfers(self): + """Returns either a list of all the user's transfers, or a list of + transfers made in the given gameweek. + + Information is taken from e.g.: + https://fantasy.premierleague.com/api/entry/91928/transfers/ + + :rtype: list + """ return await fetch(self._session, API_URLS["user_transfers"].format(getattr(self, "id"))) @property diff --git a/setup.py b/setup.py index b1ff261..36847b4 100644 --- a/setup.py +++ b/setup.py @@ -27,6 +27,7 @@ "Source": "https://github.com/amosbastian/fpl" }, install_requires=[ + "async_property", "Click", "colorama", "codecov", @@ -36,7 +37,8 @@ "pytest-aiohttp", "pytest-cov", "pytest-mock", - "pytest", 'requests' + "pytest", + "requests" ], entry_points=""" [console_scripts]