Git Product home page Git Product logo

uberfastman / yfpy Goto Github PK

View Code? Open in Web Editor NEW
166.0 10.0 43.0 8.78 MB

Python API wrapper for the Yahoo Fantasy Sports public API (supports NFL, NHL, MLB, and NBA).

Home Page: https://pypi.org/project/yfpy/

License: GNU General Public License v3.0

Python 97.97% Makefile 0.58% Batchfile 0.25% CSS 0.90% Dockerfile 0.28% Shell 0.03%
yahoo-fantasy-sports fantasy-leagues python-api-wrapper yahoo-api yahoo-fantasy fantasy-football fantasyfootball python python3 yahoo

yfpy's Introduction

YFPY - Yahoo Fantasy Sports API Wrapper

Python API wrapper for the Yahoo Fantasy Sports public API

Author: Wren J. R. (uberfastman)

GitHub release (latest SemVer) GitHub tag (latest SemVer) GitHub Workflow Status (with event)

PyPI PyPI PyPI PyPI


Do you like the YFPY API wrapper? Star the repository on GitHub and please consider helping support its ongoing development:

Cryptocurrency Address
Bitcoin (BTC) bc1qataspvklhewtswm357m0677q4raag5new2xt3e
Ethereum (ETH) 0x5eAa522e66a90577D49e9E72f253EC952CDB4059


READ THE DOCS HERE!
Detailed documentation on YFPY can be found at https://yfpy.uberfastman.com.

Table of Contents


About

YFPY is a comprehensive wrapper around the Yahoo Fantasy Sports API. It allows for easy retrieval and parsing of almost any data you might wish to extract and use from any Yahoo fantasy league to which your Yahoo account has access (or for public leagues). The primary focus of this wrapper is on fantasy football (NFL), but it also supports usage with fantasy hockey (NHL), fantasy baseball (MLB), and fantasy basketball (NBA).


Installation

Pip

  • If you wish to use YFPY within another project, from within your project directory, run

    pip install yfpy

    or add yfpy to your project requirements.txt.

Manual

  • If you wish to download and use YFPY locally, clone the git repository:
    git clone [email protected]:uberfastman/yfpy.git

Setup

Yahoo Developer Network App

In order to use YFPY with private fantasy leagues, you must set up an app on your Yahoo account to allow access. Follow the step-by-step guide below for instructions on how to do so, or see Getting Started in the Yahoo Developer Network docs for more details.

Note: If you are only planning on using YFPY to pull "read only" data from public leagues, you do not need to do this.

  • Log in to a Yahoo account with access to whatever fantasy leagues from which you wish to retrieve data.
  • Go to https://developer.yahoo.com/apps/create/ and create an app (you must be logged into your Yahoo account as stated above). For the app, select the following options:
    • Application Name (Required): yfpy (you can name your app whatever you want, but this is just an example).
    • Application Type (Required): select the Installed Application radio button.
    • Description (Optional): you may write a short description of what the app does.
    • Home Page URL (Optional): if you have a web address related to your app you may add it here.
    • Redirect URI(s) (Required): this field must contain a valid redirect address, so you can use https://localhost:8080
    • API Permissions (Required): check the Fantasy Sports checkbox. You can leave the Read option selected (appears in an accordion expansion underneath the Fantasy Sports checkbox once you select it).
    • Click the Create App button.
    • Once the app is created, it should redirect you to a page for your app, which will show both a Client ID and a Client Secret.
    • Make a copy of auth/private.template.json, rename it to just private.json, and copy the Client ID and Client Secret values to their respective fields (make sure the strings are wrapped regular quotes (""), NOT formatted quotes (โ€œโ€)). The path to this file will be needed to point YFPY to your credentials.
    • Now you should be ready to initialize the OAuth2 connection between YFPY your Yahoo account.

Usage

Authentication

  • Follow the instructions in the Installation and Setup sections.
  • The first time you use YFPY, a browser window will open up asking you to allow your app to access your Yahoo fantasy sports data. You MUST hit allow, and then copy the verification code that pops up into the command line prompt where it will now be asking for verification, hit enter, and the OAuth2 three-legged handshake should be complete and your data should have been successfully retrieved.
  • YFPY should have now generated a token.json for you in the same directory where you stored your private.json credentials, and for all subsequent runs of your app, you should be able to keep retrieving Yahoo fantasy sports data using YFPY without re-verifying, since the generated refresh token should now just renew whenever you use the same token.json file to authenticate your app.

Querying the Yahoo Fantasy Sports API

  • See the documentation on the yfpy.query.YahooFantasySportsQuery class for example usage of all available queries.
  • See quickstart/quickstart.py for example usage output.
    • Uncomment/comment out whichever configuration values in their respective functions with which you wish to experiment.
    • Uncomment/comment out whichever query lines in the RUN QUERIES section you wish to run.
    • Uncomment/comment out whichever query lines in the CHECK FOR MISSING DATA FIELDS section you wish to check for any new/missing data fields returned by the Yahoo Sports Fantasy Football API.

Docker

YFPY can be used within Docker for a more seamless, platform-agnostic experience.

  • Run the Docker container (pulls the YFPY Docker image from GitHub Package Registry):
    docker compose up
  • You can then run commands in the Docker container in two different ways:
    • Connect to the running container and run commands from within it:
      docker exec -it yfpy-package-1 bash
      Then:
      python quickstart/quickstart.py
    • Send commands to the running container from your host machine:
      docker exec -i yfpy-package-1 bash -c "python quickstart/quickstart.py"
Docker Development (optional)
  • Run the Docker container for local development (mount all local code into container):
    docker compose -f compose.yaml -f compose.dev.yaml up
Docker Image Deployment

See DEPLOYMENT.md for Docker image deployment.


Testing

YFPY has a collection of fully functional code snippets that can be run using pytest. These snippets demonstrate how to use YFPY to retrieve your Yahoo Fantasy Sports data.

Unit

  • See the test/unit directory for example code snippets using pytest.

Integration

  • See the test/integration directory for example code snippets using pytest.
  • Before running any integration tests, make a copy of auth/.env.template in the auth/ directory and rename it to .env.
  • Copy your Yahoo Client ID and Client Secret into the environment variables in .env so that pytest can use them when hitting the Yahoo Fantasy Sports API.
  • If this is the first time running pytest with your Yahoo API credentials, you MUST allow interactive prompts within pytest by using the -s flag.
  • The fixture values in test/integration/conftest.py are defined in quickstart/quickstart.py, and can be changed for testing by uncommenting/commenting out the values inside each respective function.

Running

  • You can invoke all pytest tests (both integration test and unit tests) by running the below from the root directory:
    • pytest -v -s
  • If you want to run only the unit tests, you can run:
    • pytest -v -s -m unit
  • If you want to run only the integration tests, you can run:
    • pytest -v -s -m integration

Dependencies

Platform

YFPY has only been tested extensively on macOS, but is written to be platform-agnostic, and seems to work without issue on Windows and Linux.

Python

YFPY requires Python 3.8 or later, and has been tested through Python 3.11.

Development

Direct project dependencies can be viewed in requirements.txt, and additional development and build dependencies (not including transitive dependencies) can be viewed in requirements-dev.txt.


Troubleshooting

Yahoo Fantasy Sports API

Occasionally when you use the Yahoo Fantasy Sports API, there are hangups on the other end that can cause data not to transmit, and you might encounter an error similar to this:

Traceback (most recent call last):
  File "yfpy-app.py", line 114, in <module>
    var = app.run()
  File "/Users/your_username/PATH/T0/LOCAL/PROJECT/yfpy-app.py", line 429, in run
    for team in team_standings:
IndexError: list index out of range

Typically, when the above error (or a similar error) occurs, it simply means that one of the Yahoo Fantasy Sports API calls failed and so no data was retrieved. This can be fixed by simply re-running data query.

yfpy's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yfpy's Issues

[Feature Request] Team Stats for Season for H2H League with Categories

Description

Currently yfpy is able to query the teasm stats for a points league, looking to see if Team Stats for a H2H league with categories can be brought in. E.g. For MLB, retrieving R/HR/etc. category stats for the season (may be located at something like the following: https://.fantasysports.yahoo.com/b1/<team_id>/headtoheadstats?pt=B&type=stats)

Use case

Gives the ability to see team stats within a H2H league, e.g. for considering how the team is performing in a more roto-like format.

Unexpected TypeError

Hi,

I'm getting an unexpected TypeError when I try to run import YahooFantasySportsQuery, please see below screenshot. I was able to successfully setup my oauth file and connect to my yahoo account but am unable to run queries due to this error.

type_error

Please let me know if any further info is needed to assist.

Thanks

Error Importing YFPY packages: 'type' object is not subscriptable

After upgrading to yfpy 8.0.7 from a much older version, I can no longer import the packages.

It looks like in utils.py there is some issue with Python recognizing the instance of typing.Dict as a dict object, which throws the error.

I'm fairly new to this so my apologies if this has been brought up before or if this is an issue on my end.

image

Getting "keyerror" when attempting to run quickstart.py

Description of Issue

Please put a longer description of the bug/issue/problem you are encountering here, as well as anything else you think might be relevant or helpful to reproduce the issue.

Additional Information as Applicable

Yahoo Fantasy Sports League ID

215870

Yahoo Fantasy Sports League Privacy

Public

Operating System/Environment

Windows 10

Other

Any other setup/environment/configuration information you might deem potentially relevant.

I generated a Client ID and Client Secret. The docs say this is an optional step and only needed to run if you want to run a Private league, but it seems like providing a Client ID and Client Secret is mandatory so I went ahead and setup a Yahoo Developer Network App anyway since I may need the private league feature down the road anyway.

There is no Application Type section anymore with an "Installed Application" radio button at https://developer.yahoo.com/apps/create/ but there is a "OAuth Client Type" with confidential client and public client. I selected confidential client. I also selected Fantasy Sports and read/write permissions.

When I select this, it generates a Client ID (Consumer Key) and Client Secret (Consumer Secret). I insert this into private.json as well as into quickstart.py

However this throws up an exception:

(py311baseballbot) C:\baseballbot\yfpy>python quickstart/quickstart.py
Traceback (most recent call last):
File "C:\baseballbot\yfpy\quickstart\quickstart.py", line 264, in
consumer_key=os.environ["dj0yJmk9aHFRUnhxUU5yWll5JmQ9WVdrOVZrdzJlRGwxUVZNbWNHbzlNQT09JnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PWYx"],
~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "", line 679, in getitem
KeyError: 'dj0yJmk9aHFRUnhxUU5yWll5JmQ9WVdrOVZrdzJlRGwxUVZNbWNHbzlNQT09JnM9Y29uc3VtZXJzZWNyZXQmc3Y9MCZ4PWYx'

[Feature Request] Get weekly league standings

Description

I'm in a NHL fantasy league. I was wondering if we can get the league standings given a start date and end date? Not just the current standings.

Use case

So I can visualize overtime how teams progress throughout the year.

get_league_transactions() returns single quote json property

Hi,
When querying the get_league_transactions(), a json object returns a property in single quotes
image

This returns the following error when trying to convert the object into json using json.loads(str(yahoo_query.get_league_transactions()))

returns an error of JSONDecodeError: Expecting property name enclosed in double quotes

[Feature Request] Possible to add ownership percentage by date?

Description

Hello! I am curious if the yahoo backend allows for the ability to pull player ownership percentage per specified date, similar to how the get_player_stats_by_date works?

I tired to cobble something together in a similar fashion to the current version of get_player_percent_owned_by_week, but it only returns the current date's value.

Use case

I would like to be able to parse the % ownership by date for current/past seasons to analyze trends.

401 Error After Running Queries on Loop for >1 hour

Kind of a similar issue, however I believe mine is an expired token issue.

What I'm trying to do is run the test_get_league_scoreboard_by_week() function on a thread in order to push live updates (every 30 sec) to a led matrix. So far it works flawlessly for about an hour and then 401 errors repeating. I restart the code and everything runs as it should for another hour until I hit 401's again. Looked into this in YF api documentation and it checks out that the token expires every hour.

Any thoughts on how I could code a refresh into the 401 error try/except portion? Or any thoughts in general on getting around this?

Originally posted by @Pensfan66 in #21 (comment)

New player stats data field?

Description of Issue

Got this when using the get_league_players query:

DEBUG - models.py - yfpy.models:128 - The Yahoo Fantasy Sports API includes 1 additional data fields for Player that are not included in YFPY: ['eligible_positions_to_add']

Additional Information as Applicable

Yahoo Fantasy Sports League ID

263808

Yahoo Fantasy Sports League Privacy

Private

Operating System/Environment

macOS

Other

Trouble Running test.py

Hello, I have successfully created an app with a subsequent client id/secret. As well, in test.py I have changed the auth_dir variable to the private.json file path; however, after running test.py I get the following behavior:

test_get_all_yahoo_fantasy_game_keys (main.QueryTestCase)
Retrieve all Yahoo fantasy football game keys. ... Enter verifier : hrurpuf
ERROR

It happens to every unit test and it also opens a webpage with a new verifier every time a unit test case is ran. In the readme you state the following "The path to this file will be needed to point YFPY to your credentials." Where exactly do I have to specify the private.json file path? Or could something else be wrong?

YahooAPI weekly stats url possible change

Hi again @uberfastman, I think Yahoo might've pulled a quick one on you and changed the call for weekly stats. Just want go get your opinion, and if they did indeed make a change I'd be glad to work on it and send another pull request.

I came across this in get_player_stats_by_week, specifically this line. The week specification is given by

;type=week;week=" + str(chosen_week),,

however I was noticing that this wasn't returning any player stats.

Looking at Yahoo's wall of "documentation" that I'm sure you're familiar with, I found their week was specified via

https://fantasysports.yahooapis.com/fantasy/v2/team//roster;week=10

Changing our friendly line 2149/2150 to

;week=" + str(chosen_week),

appeared to solve the problem. Not sure if this is something NHL specific.

Not anything urgent, don't rush to check it out. Thanks again for all your work!

Support for retrieving complete player stats

The method get_player_stats_by_date currently utilizes the URL {base_url}/league/{league_key}/players;. However, according to the official Yahoo Fantasy Sports API documentation, there's an alternative URL {base_url}/players; available.

The key distinction between the two is that the player stats fetched from the league resource only encompass limited categories defined in league metadata, while the alternative URL provides comprehensive statistics for the players.

Kindly consider adding support to use the latter URL to obtain a more detailed data.

[Bug] Team key does not exist (for a league I'm not even in...)

Description of Issue

I am using the examples from the getting started docs. When I try to list the league ids, I get this very specific error:

% python3 ./quickstart.py
2024-02-26 03:05:01.035 - ERROR - query.py - yfpy.query:205 - Attempt to retrieve data at URL https://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games;codes=nhl/teams/?format=json failed with error: "Team key 39.l.32941.t.10 does not exist."
Traceback (most recent call last):
  File "/Users/ijcd/work/fantasy/trials/yfpy/./quickstart.py", line 290, in <module>
    print(repr(yahoo_query.get_user_teams()))
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yfpy/query.py", line 967, in get_user_teams
    return self.query(
           ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yfpy/query.py", line 263, in query
    response = self.get_response(url)
               ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/yfpy/query.py", line 206, in get_response
    raise YahooFantasySportsDataNotFound(error_msg, url=response.url)
yfpy.exceptions.YahooFantasySportsDataNotFound: Attempt to retrieve data at URL https://fantasysports.yahooapis.com/fantasy/v2/users;use_login=1/games;codes=nhl/teams/?format=json failed with error: "Team key 39.l.32941.t.10 does not exist."

Additional Information as Applicable

The odd thing about this is that I'm not in this league as near as I can tell. Oddly, though, If I go to this league in NHL, I can see it, but maybe that's just because it is public. This may be a red herring.

https://hockey.fantasysports.yahoo.com/hockey/32941

Yahoo Fantasy Sports League ID

42179

Yahoo Fantasy Sports League Privacy

Private

Operating System/Environment

macOS

Other

It seems like that team ID is for something else... I think the format is Game.l.League.t.Team -- I'm not sure what game 39 is... but it seems that maybe it was MLB 2002? Something very odd is going on here -- I'm worried that there is bad data in the API for my user... no idea how it would have got there or how to fix it -- I can't seem to find this league (unless it is that NHL one... but the league id matches without the game matching...)

Running it in a container

Have you ever run this package in a container setup? I guess because of python official image, or lightweight linux like alphin, does not come with a browser. Another reason I can think of is the callback (localhost:8080) is not working, albeit I open the port during start. Any tips is welcome.

KeyError in example

It seems that something is not quite right, or maybe I've not followed the instructions close enough. When I try to run the test_yfpf.py file I'm getting a KeyError: 'YFPY_CONSUMER_KEY'

  1. pip installed yfpy
  2. I followed all the steps and successfully got a ConsumerSecret and ConsumerKey from Yahoo.
  3. Created a copy of EXAMPLE_private.json into a local folder and renamed it to private.json.
  4. Copied test_yfpy.py into a folder
  5. Change league id to my own league id
  6. Run python -m test_yfpy.py
  7. KeyError

So I figured maybe this is because there was a change and environment variables were used instead, so I created a .env file (again same folder), and run python -m test_yfpy.py, same issue.

Running on Windows 10

Request: get_league_transactions() Waiver FAB bids and Trade draft picks

Hello! I have been using the query.get_league_transactions() method to parse transaction data for my yahoo fantasy hockey league. I have noticed that there are two bits of information that are unavailable at the moment. I am currently using version 13.0.0.

1. FAB Spent on Waiver acquisitions: In cases where a GM has spent FAB to acquire a player off of waivers, the amount of $ spent is currently unavailable through the output. Is there a way to pull the FAB $ spent data?

(sample output for a transaction that has FAB $ spent):

{'transaction': {
   "players": [
     {
       "player": {
         "display_position": "C",
         "editorial_team_abbr": "CGY",
         "name": {
           "ascii_first": "Mikael",
           "ascii_last": "Backlund",
           "first": "Mikael",
           "full": "Mikael Backlund",
           "last": "Backlund"
         },
         "player_id": 4263,
         "player_key": "419.p.4263",
         "position_type": "P",
         "transaction_data": {
           "destination_team_key": "xxx.l.xxxxx.t.xx",
           "destination_team_name": "xxxxxxxxx",
           "destination_type": "team",
           "source_type": "waivers",
           "type": "add"
         }
       }
     },
     {
       "player": {
         "display_position": "D",
         "editorial_team_abbr": "TOR",
         "name": {
           "ascii_first": "Mark",
           "ascii_last": "Giordano",
           "first": "Mark",
           "full": "Mark Giordano",
           "last": "Giordano"
         },
         "player_id": 3614,
         "player_key": "419.p.3614",
         "position_type": "P",
         "transaction_data": {
           "destination_type": "waivers",
           "source_team_key": "xxx.l.xxxxx.t.xx",
           "source_team_name": "xxxxxxxxxxx",
           "source_type": "team",
           "type": "drop"
         }
       }
     }
   ],
   "status": "successful",
   "timestamp": 1678438787,
   "transaction_id": 1582,
   "transaction_key": "xxx.l.xxxxx.tr.1582",
   "type": "add/drop"
 }}

2. Draft Picks in Trades: In trades involving draft picks, the draft pick information is not displayed. Is there any way to add these picks to the trade transaction information?

(sample output where a few draft picks should be included):

 {'transaction': {
   "players": [
     {
       "player": {
         "display_position": "RW",
         "editorial_team_abbr": "VAN",
         "name": {
           "ascii_first": "Brock",
           "ascii_last": "Boeser",
           "first": "Brock",
           "full": "Brock Boeser",
           "last": "Boeser"
         },
         "player_id": 6765,
         "player_key": "419.p.6765",
         "position_type": "P",
         "transaction_data": {
           "destination_team_key": "xxx.l.xxxxxx.t.xx",
           "destination_team_name": "xxxxxxxxxxx",
           "destination_type": "team",
           "source_team_key": "yyy.l.yyyyy.t.y",
           "source_team_name": "yyyyyyyy",
           "source_type": "team",
           "type": "trade"
         }
       }
     },
     {
       "player": {
         "display_position": "LW",
         "editorial_team_abbr": "NSH",
         "name": {
           "ascii_first": "Filip",
           "ascii_last": "Forsberg",
           "first": "Filip",
           "full": "Filip Forsberg",
           "last": "Forsberg"
         },
         "player_id": 5691,
         "player_key": "419.p.5691",
         "position_type": "P",
         "transaction_data": {
           "destination_team_key": "yyy.l.yyyyy.t.y",
           "destination_team_name": "yyyyyyyyyy",
           "destination_type": "team",
           "source_team_key": "xxx.l.xxxxxx.t.xxx",
           "source_team_name": "xxxxxxxx",
           "source_type": "team",
           "type": "trade"
         }
       }
     }
   ],
   "status": "successful",
   "timestamp": 1676019280,
   "tradee_team_key": "xxx.l.xxxxxx.t.xx",
   "tradee_team_name": "xxxxxxxxxxx",
   "trader_team_key": "yyy.l.yyyyyy.t.y",
   "trader_team_name": "yyyyyyyyy",
   "transaction_id": 1334,
   "transaction_key": "xxx.l.xxxxx.tr.1334",
   "type": "trade"
 }}

Any chance this data can be parsed and added to a future release? Thanks so much for all the hard work!

AttributeError: 'OAuth2' object has no attribute 'consumer_key'

Hello, thank you for putting together this package. I followed the install & setup steps, generated token.json and saved it along with private.json in my /auth folder. I'm having authentication issues with using the class YahooFantasySportsQuery, e.g.,

from pathlib import Path
from yfpy.query import YahooFantasySportsQuery
query = YahooFantasySportsQuery(Path("path/to/backend/auth"), league_id="xxxxx")
query.get_all_yahoo_fantasy_game_keys()

I historically have trouble with Oauth (apologies if this is just something simple I'm missing) and am unsure how to further troubleshoot:

  • Environment is local | windows | venv | python3.11.3
  • Auth directory location: c:\Users\username\Documents\GitHub\project-name\backend\auth
  • Auth directory contents: private.json, token.json (both appear to be in the correct format)

Error log below: (league id / username replaced with placeholders)

---------------------------------------------------------------------------
AttributeError: 'OAuth2' object has no attribute 'consumer_key'
AttributeError                            Traceback (most recent call last)
c:\Users\username\Documents\GitHub\project-name\backend\tests.ipynb Cell 3 line 3
      1 from pathlib import Path
      2 from yfpy.query import YahooFantasySportsQuery
----> 3 query = YahooFantasySportsQuery(Path("C:/Users/username/Documents/GitHub/project-name/backend/auth"), league_id="xxxxxx")
      4 # query.get_all_yahoo_fantasy_game_keys()

File c:\Users\username\Documents\GitHub\project-name\backend\venv\Lib\site-packages\yfpy\query.py:124, in YahooFantasySportsQuery.__init__(self, auth_dir, league_id, game_id, game_code, offline, all_output_as_json_str, consumer_key, consumer_secret, browser_callback, retries, backoff)
    121 self.executed_queries: List[Dict[str, Any]] = []
    123 if not self.offline:
--> 124     self._authenticate()

File c:\Users\username\Documents\GitHub\project-name\backend\venv\Lib\site-packages\yfpy\query.py:165, in YahooFantasySportsQuery._authenticate(self)
    161     self._yahoo_access_token = auth_info["access_token"]
    163 # complete OAuth2 3-legged handshake by either refreshing existing token or requesting account access
    164 # and returning a verification code to input to the command line prompt
--> 165 self.oauth = OAuth2(None, None, from_file=token_file_path, browser_callback=self._browser_callback)
    166 if not self.oauth.token_is_valid():
    167     self.oauth.refresh_access_token()

File c:\Users\username\Documents\GitHub\project-name\backend\venv\Lib\site-packages\yahoo_oauth\oauth.py:236, in OAuth2.__init__(self, consumer_key, consumer_secret, **kwargs)
    235 def __init__(self, consumer_key, consumer_secret, **kwargs):
--> 236     super(OAuth2, self).__init__('oauth2', consumer_key, consumer_secret, **kwargs)
...
     80     'base_url': vars(self).get('base_url', None)
     81 })
     83 # Defining oauth service
AttributeError: 'OAuth2' object has no attribute 'consumer_key'

Setup Question

I have gotten to the setup step:

Make a copy of examples/EXAMPLE-private.json, rename it to just private.json, and copy the Client ID and Client Secret values to their respective fields (make sure the strings are wrapped regular quotes.

However I cannot find the "example" link. I have the App ID, Client ID, and Client Secret values so that part is taken care of.

'all_output_as_json=True ' in query object prevents access to its own methods

I wanted to output as json the queries generated from the YahooFantasySportsQuery so I set the above parameter to True. I get the following error:
File "/Users/lukechu/Projects/TracyBowl/lib/python3.8/site-packages/yfpy/query.py", line 780, in get_league_key return self.get_game_metadata_by_game_id(self.game_id).game_key + ".l." + self.league_id AttributeError: 'str' object has no attribute 'game_key'

As an alternative I tried calling clean_data_dict() method on query output of a Player object, specifically on query.get_team_roster_player_stats_by_week(manager_id, week), and checked the types of both keys and values, and they were native Python types.

But I was unable to serialize the cleaned Player dict via json.dump() with the following error:
raise TypeError(f'Object of type {o.__class__.__name__} ' TypeError: Object of type Stat is not JSON serializable

Not sure how that object type was being picked up or how it remains for the cleaned Player dict.

Any ideas?

Yahoo data access error handling

Gracefully handle when you don't have permission to access Yahoo data, but it still returns valid json, but with an error message.

Typing inconsistencies

I am trying to use query.get_league_teams, and am expecting a List[Team], but am instead getting a List[dict].

Is there a better way to do this so I get the types I am expecting?

As an example, this outputs "dict", but should output "Team", based on the Mypy types.

query = YahooFantasySportsQuery(Path("/credentials/yfpy_auth"), league_id=league_id, browser_callback=False)
league_teams = query.get_league_teams()
logger.info(type(league_teams[0]))

HTTPError: 400 on yahoo_query.get_league_players() call

HTTPError: 400 Client Error: Bad Request for url: https://fantasysports.yahooapis.com/fantasy/v2/league/411.l.****/players;start=1425?format=json

Not sure why this is popping up. Running the same script for a few days and only now is this throwing me an error. I don't think it's a data limit error since it's not 999 like the source comments suggest.

Anyone experiencing the same thing? I might give it another 24hrs and then dig into it some more.

Learning oppurtunity

I'm very novice at developing/programming but want to start the learning path. I'm a pretty adamant smart home user (home assistant) and would love to build an integration for Yahoo Sports.

If anyone would like to team up and take me under your wings I'd love to work with you to bring this project to life! Thanks.

Player Data

Within the query "get_league_players()" only the first 25 players are queried. To correct this problem, and allow to pull the full scope of the players. I added "start" variable within the function changing the query to:

def get_league_players(self, start): return self.query( "https://fantasysports.yahooapis.com/fantasy/v2/league/" + self.get_league_key() + "/players;start=" + str(start), ["league", "players"])

Start should occur in multiples of 25.

Yahoo Fantasy API Potential Rate Limits

@uberfastman I'm wondering if you ever ran into any issues with the number of requests you could make during your development and use of this repo. I haven't been able to find any documentation with Yahoo on rate limits, so I'm just curious if you had any issues as well.

An example where this might be a problem is when I'm trying to collect matchup data for each season, and for each week within those seasons. I'll repeatedly make a call to query.get_league_scoreboard_by_week(wk). If I try to iterate over 2 seasons or so it will result in the following connection error:

http.client.RemoteDisconnected: Remote end closed connection without response

EXAMPLE.private.json Location

The file referenced in the readme has moved from test/integration/EXAMPLE.private.json to auth/EXAMPLE.private.json and should be updated accordingly.

[Bug] "get_team_roster_player_stats_by_week" returns player stats for a single day, not week

Description of Issue

I am running query.get_team_roster_player_stats_by_week(team_id=4). The function lists player_points.coverage_type as "week" and player_points.week as "1". When I run the function, it's returning player_points.coverage_type = "date" and then giving the current date, instead of the week. This results in the incorrect stats being displayed.

If I run query.get_team_roster_player_stats_by_week(team_id=4, chosen_week=1), it will choose "2023-10-29" as the "date", when it should display 1 as the week.

Additional Information as Applicable

I'm doing this for Fantasy Basketball. This may not be a bug for Fantasy Football.

Yahoo Fantasy Sports League ID

43993

Yahoo Fantasy Sports League Privacy

Private

Operating System/Environment

Windows

Other

None

Clean up returned data structures

Currently, when returning lists of objects, YFPY returns them as lists of dictionaries, each with a single key corresponding to the data type of the object value (so a list of Game instances is returned as a list of dictionaries, each with the single key "game", and a single value corresponding to that key that is the YFPY Game object).

The reason for the above is so that unpack_data can properly parse and cast/deserialize the JSON both returned from the Yahoo API and from saved JSON data files.

For an improved user experience and a clearer data structure hierarchy, it would be nice to instead simply return a list of YFPY Game objects. However, in order to do so a new approach to detecting the correct data type will need to be built.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.