Skip to content

Commit b534c0c

Browse files
committed
FPL now requires sessionin as well
1 parent fab34c9 commit b534c0c

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

lazyfpl/conf.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
class _Env(BaseSettings):
11-
model_config = SettingsConfigDict(env_file='.env', env_file_encoding='utf-8')
11+
model_config = SettingsConfigDict(env_file=".env", env_file_encoding="utf-8")
1212
backtrace: int = Field(
1313
alias="FPL_BACKTRACE",
1414
default=3,
@@ -32,6 +32,10 @@ class _Env(BaseSettings):
3232
alias="FPL_PROFILE",
3333
default="",
3434
)
35+
sessionid: str = Field(
36+
alias="FPL_SESSIONID",
37+
default="",
38+
)
3539
tabulate_format: str = Field(
3640
alias="FPL_TABULATE_FORMAT",
3741
default="tsv",
@@ -47,5 +51,6 @@ class _Env(BaseSettings):
4751
debug: typing.Final = _Env().debug
4852
lookahead: typing.Final = _Env().lookahead
4953
profile: typing.Final = _Env().profile
54+
sessionid: typing.Final = _Env().sessionid
5055
tabulate_format: typing.Final = _Env().tabulate_format
5156
teamid: typing.Final = _Env().teamid

lazyfpl/fetch.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,18 +149,22 @@ def picks() -> list[Persona]:
149149
"""
150150
Fetches and returns the current team picks from the Fantasy Premier League API.
151151
"""
152-
if not conf.teamid or not conf.profile:
152+
if not conf.teamid or not conf.profile or not conf.sessionid:
153153
raise RuntimeError(
154-
"Env. FPL-teamid and FPL-cookie/profile must be set. FPL-team id "
154+
"Env. FPL-teamid and FPL-cookie/profile/sessionid must be set. FPL-team id "
155155
"from URL and cookie 'pl_profile' from 'application' in chrome."
156156
)
157157

158158
response = requests.get(
159159
f"https://fantasy.premierleague.com/api/my-team/{conf.teamid}/",
160-
cookies={"pl_profile": conf.profile},
160+
cookies={
161+
"pl_profile": conf.profile,
162+
"sessionid": conf.sessionid,
163+
},
161164
)
165+
162166
if not response:
163-
raise RuntimeError("Non 2xx status code.")
167+
raise RuntimeError("Non 2xx status code.", response)
164168

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

0 commit comments

Comments
 (0)