Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get NBA player rank and projected rank? #22

Open
salbro opened this issue Jan 31, 2021 · 4 comments
Open

Get NBA player rank and projected rank? #22

salbro opened this issue Jan 31, 2021 · 4 comments

Comments

@salbro
Copy link

salbro commented Jan 31, 2021

Is there a way to get an NBA player's rank and projected rank? I can't seem to figure it out.

@JaumeClave
Copy link

JaumeClave commented Feb 5, 2021

Bump. I would love to figure this out as well. From what I can tell, the Players Collection of the Yahoo Fantasy Sports API can return player rank. I can't seem to find out how to do this with this library.

Thank you for this resource. It is incredibly useful!

@JaumeClave
Copy link

JaumeClave commented Feb 5, 2021

I think I have figured it out @salbro. The Yhandler class inside yhandler.py has a get() function (here). You can append your URI to it and return player original rank or actual rank.

from yahoo_oauth import OAuth2
from yahoo_fantasy_api import yhandler
sc = OAuth2(None, None, from_file={your_file_path})
yh = yhandler.YHandler(sc)
yh.get(f"/league/{your_league_id}/players;status=FA;sort=AR")

FA, as documented in this library, returns league free agents and AR will return the actual rank based on your league settings. This repo has better documentation than the Yahoo Fantasy Sports API documentation. I believe Original Rank OR is projected rank but I am not 100% on that.

@salbro
Copy link
Author

salbro commented Feb 6, 2021

Thanks, JaumeClave! That's really helpful. For posterity, here's some code to fetch all players ranks (and name and keys) from a league object:

def get_player_ranks(league):
    all_ranks = {}
    rank_start = 0
    while True:
        ranked_players = league.yhandler.get(f"/league/{league.league_id}/players;sort=AR;start={rank_start}")
        player_dict = ranked_players['fantasy_content']['league'][1]['players']
        if player_dict == []:
            break
        ranks = {}
        for maybe_rank, player in player_dict.items():
            if maybe_rank == 'count':
                continue
            player_key = player['player'][0][0]['player_key'] 
            player_id = int(player['player'][0][1]['player_id'])
            player_full_name = player['player'][0][2]['name']['full']
            ranks[player_id] = {'rank': rank_start + int(maybe_rank) + 1,
                                'key': player_key,
                                'full name': player_full_name}
        all_ranks.update(ranks)
        rank_start += 25
    return all_ranks

@JaumeClave
Copy link

@salbro - Yeah, that is great! Thanks for sharing that. I'll be using it in my project!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants