Ejemplo n.º 1
0
    def get_scoreboards(self, league=None, week=None):
        if league:
            if league != self.last_league:
                self._set_league(league)
                self.league = yfa.League(self.sc, league)

        if not self.league:
            if not league:
                league = self.last_league
            self.league = yfa.League(self.sc, league)

        matchups = self.league.matchups(week)
        return matchups['fantasy_content']['league'][1]['scoreboard']['0'][
            'matchups']
Ejemplo n.º 2
0
    def __init__(self, cfg, reset_cache):
        self.logger = logging.getLogger()
        self.cfg = cfg
        self.sc = OAuth2(None, None, from_file=cfg['Connection']['oauthFile'])
        self.lg = yfa.League(self.sc, cfg['League']['id'])
        self.tm = self.lg.to_team(self.lg.team_key())
        self.tm_cache = utils.TeamCache(self.cfg, self.lg.team_key())
        self.lg_cache = utils.LeagueCache(self.cfg)
        if reset_cache:
            self.tm_cache.remove()
            self.lg_cache.remove()
        self.load_league_statics()
        self.pred_bldr = None
        self.my_team_bldr = self._construct_roster_builder()
        self.ppool = None
        Scorer = self._get_scorer_class()
        self.scorer = Scorer(self.cfg)
        Display = self._get_display_class()
        self.display = Display(self.cfg)
        self.lineup = None
        self.bench = []
        self.injury_reserve = []
        self.opp_sum = None
        self.opp_team_name = None

        self.init_prediction_builder()
        self.score_comparer = ScoreComparer(self.cfg, self.scorer,
                                            self.fetch_league_lineups())
        self.fetch_player_pool()
        self.sync_lineup()
        self.pick_injury_reserve()
        self._auto_pick_opponent()
Ejemplo n.º 3
0
def leag(idx = -1, file = '../trade_managment/oauth2.json'):
    '''
    function to just return the leauge to abstract 
    away the authentication in other files
    '''
    oauth = OAuth2(None, None, from_file=file)
    g = yfa.Game(oauth, 'nhl')
    lg = yfa.League(oauth, g.league_ids()[-1])
    return lg
Ejemplo n.º 4
0
    def scan_league(self, league_id=None):
        if league_id:
            lid = league_id
            self._set_league(lid)
        else:
            lid = self.last_league
        self.league = yfa.League(self.sc, lid)
        if self.lake_leagues:
            league_data = self.lake_leagues
        else:
            league_data = dict()
        teams = self.league.teams()
        league_data.update({
            lid: {
                'year':
                self.league.settings()['season'],
                'guids': [
                    team['managers'][0]['manager']['guid']
                    for _, team in teams.items()
                ]
            }
        })
        self.lake_leagues = league_data

        if self.lake_players:
            player_data = self.lake_players
        else:
            player_data = dict()
        for _, team in teams.items():
            guid = team['managers'][0]['manager']['guid']
            team_info = player_data.get(guid)
            if team_info:
                if lid not in team_info['lids']:
                    team_info['lids'].append(lid)
                if team['name'] not in team_info['names']:
                    team_info['names'].append(team['name'])
            else:
                team_info = {'lids': [lid], 'names': [team['name']]}
            player_data.update({guid: team_info})
        self.lake_players = player_data

        return league_data, player_data
Ejemplo n.º 5
0
 def __init__(self, sc, lid):
     self.lid = lid
     self.sc = sc
     self.league = yfa.League(self.sc, league_id=lid)
     self.handler = yfa.yhandler.YHandler(sc)
Ejemplo n.º 6
0
def mock_league(sc):
    lg = yfa.League(sc, '370.l.56877')
    lg.inject_yhandler(mock_yhandler.YHandler())
    yield lg
Ejemplo n.º 7
0
def mock_nhl_league(sc):
    lg = yfa.League(sc, '396.l.21484')
    lg.inject_yhandler(mock_yhandler.YHandler())
    yield lg
Ejemplo n.º 8
0
  <year>     Will restrict all leagues listed to this year.
"""
from docopt import docopt
from yahoo_oauth import OAuth2
import yahoo_fantasy_api as yfa
import logging

if __name__ == '__main__':
    args = docopt(__doc__, version='1.0')
    logging.basicConfig(
        filename='cli.log',
        level=logging.INFO,
        format='%(asctime)s.%(msecs)03d %(module)s-%(funcName)s: %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S')
    logging.getLogger('yahoo_oauth').setLevel('WARNING')
    logging.getLogger('chardet.charsetprober').setLevel('WARNING')
    sc = OAuth2(None, None, from_file=args['<json>'])
    gm = yfa.Game(sc, args['<sport>'])
    league_ids = gm.league_ids(year=args['<year>'])
    for league_id in league_ids:
        # Older leagues have this "auto" in that, which we cannot dump any
        # particulars about.
        if "auto" not in league_id:
            lg = yfa.League(sc, league_id)
            settings = lg.settings()
            print("{:30} {:15}".format(settings['name'], league_id))
            teams = lg.teams()
            for team in teams:
                print("    {:30} {:15}".format(team['name'], team['team_key']))
            print("")