uberfastman / fantasy-football-metrics-weekly-report

Command line application to create weekly reports (containing stats, metrics, and rankings) for Fantasy Football leagues on the following platforms: Yahoo, Fleaflicker, Sleeper, ESPN.
GNU General Public License v3.0
179 stars 43 forks source link

Yahoo League "KeyError: scoreboard" #178

Closed MeanGreen256 closed 1 year ago

MeanGreen256 commented 1 year ago

Just pulled the latest version of the metrics weekly repot, setup the config.ini and private.json. I ran the docker compose and then the main.py script, after selecting default league and default week I get the following backtrace (note I'm running this on macOs):

Traceback (most recent call last): File "/app/main.py", line 267, in <module> report = select_league( File "/app/main.py", line 154, in select_league return FantasyFootballReport(week_for_report=week_for_report, File "/app/report/builder.py", line 109, in __init__ self.league = league_data_factory( File "/app/utils/report_tools.py", line 465, in league_data_factory yahoo_league = YahooLeagueData( File "/app/dao/platforms/yahoo.py", line 160, in __init__ self.matchups_by_week[wk] = self.yahoo_data.retrieve( File "/usr/local/lib/python3.9/site-packages/yfpy/data.py", line 116, in retrieve return self.get(yf_query, params) File "/usr/local/lib/python3.9/site-packages/yfpy/data.py", line 43, in get return yf_query(**params) File "/usr/local/lib/python3.9/site-packages/yfpy/query.py", line 1257, in get_league_matchups_by_week return self.query( File "/usr/local/lib/python3.9/site-packages/yfpy/query.py", line 160, in query raw_response_data = reformat_json_list(raw_response_data)[data_key_list[i]] File "/usr/local/lib/python3.9/collections/__init__.py", line 941, in __getitem__ return self.__missing__(key) # support subclasses that define __missing__ File "/usr/local/lib/python3.9/collections/__init__.py", line 933, in __missing__ raise KeyError(key) KeyError: 'scoreboard'

uberfastman commented 1 year ago

Hi @MeanGreen256, what I'm guessing is that you might have used the report app before, and when I upgraded it this season I also upgraded the YFPY dependency library as well, so you would need to rebuild the docker images by running docker compose up -d --build (or just running docker compose build followed by docker compose up -d, which will then install the latest dependencies the app needs to run!

I'm closing this as based on the stack trace I think that's the issue, but please feel free to open it again if it's still a problem.

MeanGreen256 commented 1 year ago

Hey @uberfastman. I took your advice and started with a clean repo of the application. I brought in the yahoo configuration for ID and private key. I deleted the old docker images and built a clean one using your instructions as well. I'm still getting the same "scoreboard" error

fantasy-football-metrics-weekly-report % docker exec -it fantasy-football-metrics-weekly-report-app-1 python main.py 2022-10-13 20:13:45,854 - utils.report_tools - INFO - The Fantasy Football Metrics Weekly Report app is up to date and running v13.0.2. Generate report for default league? (y/n) -> y Generate report for default week? (y/n) -> y 2022-10-13 20:13:54,080 - report.builder - INFO - Generating Yahoo Fantasy Football report with settings: league id: 654597 game id: nfl week: selected/default save_data: False refresh_web_data: False playoff_prob_sims: None break_ties: False dq_ce: False dev_offline: False test: False on Oct 13, 2022... 2022-10-13 20:13:54,103 - report.builder - INFO - Retrieving fantasy football data from Yahoo API... Traceback (most recent call last): File "/app/main.py", line 267, in <module> report = select_league( File "/app/main.py", line 154, in select_league return FantasyFootballReport(week_for_report=week_for_report, File "/app/report/builder.py", line 109, in __init__ self.league = league_data_factory( File "/app/utils/report_tools.py", line 465, in league_data_factory yahoo_league = YahooLeagueData( File "/app/dao/platforms/yahoo.py", line 160, in __init__ self.matchups_by_week[wk] = self.yahoo_data.retrieve( File "/usr/local/lib/python3.10/site-packages/yfpy/data.py", line 187, in retrieve return self.get(yf_query, params) File "/usr/local/lib/python3.10/site-packages/yfpy/data.py", line 93, in get return yf_query(**params) File "/usr/local/lib/python3.10/site-packages/yfpy/query.py", line 1682, in get_league_matchups_by_week return self.query( File "/usr/local/lib/python3.10/site-packages/yfpy/query.py", line 268, in query raw_response_data = reformat_json_list(raw_response_data)[data_key_list[i]] File "/usr/local/lib/python3.10/collections/__init__.py", line 986, in __getitem__ return self.__missing__(key) # support subclasses that define __missing__ File "/usr/local/lib/python3.10/collections/__init__.py", line 978, in __missing__ raise KeyError(key) KeyError: 'scoreboard'

uberfastman commented 1 year ago

@MeanGreen256 I'm in the process of making a little dependency upgrade update to the report app, but in the meantime, could you share some more info about your league? Is your league a head-to-head league? Is it a private league or a public league? If public, what is the league ID? Do you have any non-traditional and/or unusual settings?

MeanGreen256 commented 1 year ago

@uberfastman Yeah sure thing. The league ID is: 654597 It's a private league. It's a yahoo league, that's a normal 12 man "standard scoring" league. The only odd item for this years league is we started on week 2. I don't believe we have any other odd settings or scorings. Just a standard league.

MeanGreen256 commented 1 year ago

@uberfastman I believe I found the first issue and I believe it relates to my league having started on week 2. I edited "dao/platforms/yahoo.py" line:160 for wk in range(2, self.num_regular_season_weeks + 1):. I changed the for loop to start on week 2.

I however then ran into my next error: 2022-10-13 21:45:50,204 - report.builder - INFO - Retrieving fantasy football data from Yahoo API... Traceback (most recent call last): File "/app/main.py", line 267, in <module> report = select_league( File "/app/main.py", line 154, in select_league return FantasyFootballReport(week_for_report=week_for_report, File "/app/report/builder.py", line 109, in __init__ self.league = league_data_factory( File "/app/utils/report_tools.py", line 476, in league_data_factory return yahoo_league.map_data_to_base(BaseLeague) File "/app/dao/platforms/yahoo.py", line 448, in map_data_to_base league_team = league.teams_by_week.get(str(week)).get(str(team_id)) # type: BaseTeam AttributeError: 'NoneType' object has no attribute 'get'

uberfastman commented 1 year ago

@MeanGreen256 yeah that tidbit of info definitely explains the missing "scoreboard" key initially. I've never actually tried to run the report for a league that didn't start on week one, so I'm not surprised that it broke some things. I'll see if I can figure out a fix, although I don't have a league to test against since your league is private, so it could be tricky. Might have to end up being a feature request unfortunately.

uberfastman commented 1 year ago

@MeanGreen256 if you could do me a favor and pull the latest updates to the app in v13.1.0 (see PR #180 for reference) and try running the report for your league that started in week 2. As far as I've been able to test, it should now automatically detect the start week for Yahoo leagues (thankfully Yahoo makes that available) and adjust accordingly. I also added a command line flag (-k) that can be used to manually set the start week.

Hopefully this gets your sorted, but please reopen the issue if the fix isn't working!

uberfastman commented 1 year ago

As an update @MeanGreen256, I've actually released v14.0.0 now (dropped support for Python 3.8), which also includes all the above updates.

MeanGreen256 commented 1 year ago

@uberfastman that’s awesome man! I’ll give it a try this evening and post my feedback after I pull the new version and do a clean build.

uberfastman commented 1 year ago

@MeanGreen256 great, thanks! Every year people find new edge cases, and while I can't support them all, this one seemed easy enough! Just never had anyone try to use it with a league that started late before.

MeanGreen256 commented 1 year ago

@uberfastman I totally understand and appreciate you looking into this! I did just run a clean build and it seems to advanced further past the original issues. I've not got the following error possibly with the bad boys data: `Generate report for default league? (y/n) -> y Generate report for default week? (y/n) -> y 2022-10-14 15:52:53,587 - report.builder - INFO - Generating Yahoo Fantasy Football report with settings: league id: 654597 game id: nfl week: selected/default start_week: default=1 save_data: False refresh_web_data: False playoff_prob_sims: None break_ties: False dq_ce: False dev_offline: False test: False on Oct 14, 2022... 2022-10-14 15:52:53,609 - report.builder - INFO - Retrieving fantasy football data from Yahoo API... 2022-10-14 15:53:37,442 - report.builder - INFO - ...retrieved all fantasy football data from Yahoo API in 0:00:43.832726

2022-10-14 15:53:37,447 - report.builder - INFO - Retrieving bad boy data from https://www.usatoday.com/sports/nfl/arrests/ website... Traceback (most recent call last): File "/app/main.py", line 273, in report = select_league( File "/app/main.py", line 157, in select_league return FantasyFootballReport(week_for_report=week_for_report, File "/app/report/builder.py", line 126, in init self.bad_boy_stats = self.league.get_bad_boy_stats(self.save_data, self.dev_offline, self.refresh_web_data) File "/app/dao/base.py", line 235, in get_bad_boy_stats return BadBoyStats( File "/app/calculate/bad_boy_stats.py", line 123, in init arrests_data = resp_json["data"]["Result"] TypeError: 'int' object is not subscriptable `

uberfastman commented 1 year ago

Try waiting a bit and running it again. I was running into that this morning as well, and I suspect it was happening when that site wasn't available at times due to too much traffic or if they're having reliability issues.

MeanGreen256 commented 1 year ago

@uberfastman Will do, I'll try it every so often this afternoon and let you know the results. Thanks!

MeanGreen256 commented 1 year ago

@uberfastman Got it working and it looks beautiful. Thanks so much for the update!

uberfastman commented 1 year ago

@MeanGreen256 fantastic! So glad I could get it sorted for you, and now the bonus is the app can support leagues that start later than week 1. Thanks for all the helpful feedback!