Skip to content

Commit

Permalink
better error handling in CLI dump
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdodge committed Mar 11, 2023
1 parent 36ad23b commit c0bf710
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions yahoofantasy/cli/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from datetime import datetime
import pydash as _
import sys
from time import sleep
from yahoofantasy import Context, Team
from yahoofantasy.api.games import games
from .utils import warn, error
Expand Down Expand Up @@ -68,22 +69,20 @@ def _player_out(week_num, player, team, att_num=1):
f"Failed to fetch week {week_num} stats for {player.name.full} ({player.player_key}), trying again in 2 minutes"
)
warn(" " + str(e))
from time import sleep

sleep(120)
return _player_out(week_num, player, team, att_num + 1)


def _get_results(team, week_num):
roster = team.roster(week_num)
try:
roster = team.roster(week_num)
roster.fetch_player_stats() # pre-fetch some stats to save time
except Exception:
# TODO: Handle rate limiting here too, the requests moved here instead
# of in _player_out like they used to be now that we prefetch stats
error(
"Failed to fetch player stats, this might be due to rate limiting. Try again in 5 minutes"
"Failed to fetch player stats, this might be due to rate limiting. Trying again in 2 minutes"
)
sleep(120)
return _get_results(team, week_num)
results = []
for player in roster.players:
results.append(_player_out(week_num, player, team))
Expand Down

0 comments on commit c0bf710

Please sign in to comment.