YHandler icon indicating copy to clipboard operation
YHandler copied to clipboard

Create a comprehensive API to consume the Yahoo fantasy web services

Open BrutalSimplicity opened this issue 7 years ago • 3 comments

The YQuery API is a mess, and I believe currently may not work with people who have conda installed, but use pip to install the package.

I'd like to rewrite this using the standard Resource and Collections description Yahoo gives in their API documentation here: https://developer.yahoo.com/fantasysports/guide/

BrutalSimplicity avatar Sep 09 '16 16:09 BrutalSimplicity

I've started doing this. I created a bunch of Resource classes that have sane APIs on them, e.g. my code now looks like:

from YHandler import YahooFantasySports

handler = YahooFantasySports()

# A specific "game" in YFS talk.
game = handler.get_game('nhl')

# Only leagues that I'm currently in.
leagues = game.get_leagues(active_only=True)  # list(YahooLeagueResource) objects

# Just look at one for demonstration.
league = leagues[0]  # A single YahooLeagueResource object

print(league.is_finished)  # False

# This returns only 25 players, not sure what it's doing...
#players = league.get_players()  # list(YahooPlayerResource) objects

# Get MY team in this league.
team = league.get_team()  # YahooTeamResource object

# Get my full list of players on that team.
roster = team.get_roster()  # YahooRosterResource object

# Let's look at the first player.
player = roster.players[0]  # YahooPlayerResource object

# Get the current stats for this player, this week.
player.get_stats()  # Currently a dict

In the process of doing this...I rewrote a lot that might not really want to be upstreamed:

  • Switched from XML to JSON
  • Rewrote a couple of classes
  • Renamed things (definitely not API compatible)

Any thoughts?

clokep avatar Dec 09 '16 14:12 clokep

I definitely like the idea. When I wrote YQuery, I was just trying to put a few convenience methods to allow basic querying without having to write api strings. Some time later, I realized it would make more sense to just build a resource/collection API on top of the definitions that Yahoo provides. I haven't done much work with Python in a while, but wouldn't mind helping out with this. I think it would make this library much easier to use.

I couldn't find the changes you made in your fork. Are you just going to start a new project with this code, or end up merging into this one? At the very least it would be nice to take a look at some of what you have for this.

BrutalSimplicity avatar Dec 10 '16 20:12 BrutalSimplicity

@BrutalSimplicity I had forgotten to push my changes after forking. Oops. They're there now. See here for a diff. Some of the files were kind of gratuitously renamed to be more "pythonic"...those could be rolled back easily enough.

I'd prefer to end up merging the changes in -- I'm not a big fan of forking and people working together is always better... I should probably break up my work into small PRs, although a lot of it builds on itself.

clokep avatar Dec 10 '16 21:12 clokep