dtsong / sleeper-api-wrapper

A Python API wrapper for Sleeper's API: https://docs.sleeper.app/
MIT License
61 stars 21 forks source link

get_draft? #7

Open joshbis opened 1 year ago

joshbis commented 1 year ago

Sorry for the basic question, just getting started with Sleeper after years with ESPN. Is there a function to get a specific draft? I see that this is possible in the API, but don't see it in the package.

mmmvdb commented 1 year ago

Looks like there is a class that didn't make the docs yet.

drafts.py is what you are after.

It has a few methods in it: get_specific_draft() get_all_picks() get_traded_picks()

All of which are param-less. But the constructor to Drafts does take a draft_id.

So usage looks like it'd be something like: 1) Find your draft Id. You can use league.get_all_drafts() for that, to identify, or hard code it somewhere. 2) Create the drafts object. 3) call get_specific_draft.

Might be a bunch of work... the JSON that comes back from get_all_drafts looks almost identical to get_specific_draft's. Get specific draft has an extra dictionary called "slot_to_roster_id"

This is basically the same as the logic below, but what I used to test this out in my league (I only had the one draft):

import sleeper_wrapper as sw

league = '##################'

swleague = sw.League(league)

drafts = swleague.get_all_drafts()

draftid = drafts[0]["draft_id"]

swdrafts = sw.Drafts(draftid)

mydraft = swdrafts.get_specific_draft()