joeyagreco / sleeper

A Python wrapper for the Sleeper API.
https://pypi.org/project/sleeper/
MIT License
27 stars 6 forks source link

Request: Accurate Player Projections #37

Open dtcarls opened 4 days ago

dtcarls commented 4 days ago

Hello, would it be possible to add calculations to this library to get accurate player projections (not just standard, ppr, or half ppr via unofficial api) utilizing league scoring_settings and active rosters?

I know this isn't exactly a request that fits being a wrapper for the API, but it seems to be functionality that is missing from the sleeper coding community. I'm also open if anyone knows of this functionality existing elsewhere, I have been unable to find it.

joeyagreco commented 4 days ago

So this isn't something that I'd add to this library (like you pointed out, just an SDK)...

However, if I recall correctly this info can be extracted from GraphQL calls that the browser makes and could likely be retrieved with a few lines of Python.

I'm unable to check at the moment, if you'd like to see for yourself go in a browser (on a computer, not mobile) to any Sleeper page that shows projections for a league you're in and look at the HTTP calls being made on page load in the developer tools tab.

There should be some call being made to return player projections based on your league settings and rosters.

joeyagreco commented 4 days ago

Looks like theres a call to https://sleeper.com/graphql

With request: operationName "get_league_detail"

With query: 'query get_league_detail {\n \n league_rosters(league_id: "someleagueid"){\n league_id\n metadata\n owner_id\n co_owners\n players\n roster_id\n settings\n starters\n keepers\n reserve\n taxi\n player_map\n }\n \n \n league_users(league_id: "someleagueid"){\n avatar\n user_id\n league_id\n metadata\n settings\n display_name\n is_owner\n is_bot\n }\n…dated\n transaction_id\n type\n player_map\n waiver_budget\n }\n \n \n matchup_legs_2:matchup_legs(league_id: "someleagueid",round: 2){\n league_id\n leg\n matchup_id\n roster_id\n round\n starters\n players\n player_map\n points\n proj_points\n max_points\n custom_points\n starters_games\n picks\n bans\n subs\n }\n \n \n }'

that returns projected points in matchups for the week