Skip to content

Commit

Permalink
import async_property library
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmadden86 committed Oct 22, 2019
1 parent d24917e commit 9607731
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions fpl/fpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
25 changes: 18 additions & 7 deletions fpl/models/user.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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
"""

Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"Source": "https://github.com/amosbastian/fpl"
},
install_requires=[
"async_property",
"Click",
"colorama",
"codecov",
Expand All @@ -36,7 +37,8 @@
"pytest-aiohttp",
"pytest-cov",
"pytest-mock",
"pytest", 'requests'
"pytest",
"requests"
],
entry_points="""
[console_scripts]
Expand Down

0 comments on commit 9607731

Please sign in to comment.