Skip to content

Commit

Permalink
FPL now requires sessionin as well
Browse files Browse the repository at this point in the history
  • Loading branch information
janbjorge committed Jan 23, 2025
1 parent fab34c9 commit b534c0c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 6 additions & 1 deletion lazyfpl/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


class _Env(BaseSettings):
model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8')
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")
backtrace: int = Field(
alias="FPL_BACKTRACE",
default=3,
Expand All @@ -32,6 +32,10 @@ class _Env(BaseSettings):
alias="FPL_PROFILE",
default="",
)
sessionid: str = Field(
alias="FPL_SESSIONID",
default="",
)
tabulate_format: str = Field(
alias="FPL_TABULATE_FORMAT",
default="tsv",
Expand All @@ -47,5 +51,6 @@ class _Env(BaseSettings):
debug: typing.Final = _Env().debug
lookahead: typing.Final = _Env().lookahead
profile: typing.Final = _Env().profile
sessionid: typing.Final = _Env().sessionid
tabulate_format: typing.Final = _Env().tabulate_format
teamid: typing.Final = _Env().teamid
12 changes: 8 additions & 4 deletions lazyfpl/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,18 +149,22 @@ def picks() -> list[Persona]:
"""
Fetches and returns the current team picks from the Fantasy Premier League API.
"""
if not conf.teamid or not conf.profile:
if not conf.teamid or not conf.profile or not conf.sessionid:
raise RuntimeError(
"Env. FPL-teamid and FPL-cookie/profile must be set. FPL-team id "
"Env. FPL-teamid and FPL-cookie/profile/sessionid must be set. FPL-team id "
"from URL and cookie 'pl_profile' from 'application' in chrome."
)

response = requests.get(
f"https://fantasy.premierleague.com/api/my-team/{conf.teamid}/",
cookies={"pl_profile": conf.profile},
cookies={
"pl_profile": conf.profile,
"sessionid": conf.sessionid,
},
)

if not response:
raise RuntimeError("Non 2xx status code.")
raise RuntimeError("Non 2xx status code.", response)

return [person(p["element"]) for p in response.json()["picks"]]

Expand Down

0 comments on commit b534c0c

Please sign in to comment.