def test_fun(): sc = OAuth2(None, None, from_file='oauth2.json') gm = game.Game(sc, 'nfl') ids = gm.league_ids() print(ids) for lg_id in ids: if lg_id.find("auto") > 0: continue lg = league.League(sc, lg_id) standings = lg.standings() for i, t in zip(range(1, 100), standings): print("{} - {}".format(i, t)) league_id = gm.league_ids(year=2018) print('league id {}'.format(league_id)) lg = gm.to_league(league_id[0]) settings = lg.settings() print('settings {}'.format(settings)) team_key = lg.team_key() print('LG Team Key {}'.format(team_key)) print("Current Week = {}".format(lg.current_week())) print("Ending Week = {}".format(lg.end_week())) print(lg.week_date_range(16)) tm = team.Team(sc, team_key) print('{}'.format(pformat(tm.roster(1)))) print('{}'.format(pformat(tm.roster(2))))
def test_ids_for_year(sc): gm = game.Game(sc, 'mlb') gm.inject_yhandler(mock_yhandler.YHandler()) ids = gm.league_ids(year=2017) assert (len(ids) == 1) print(ids) assert (ids[0] == '370.l.56877')
def test_ids(sc): gm = game.Game(sc, 'mlb') gm.inject_yhandler(mock_yhandler.YHandler()) ids = gm.league_ids() for i in ids: print(i) assert (len(ids) == 12) print(ids) assert (ids[5] == '268.l.46645')
def getLeagueId(oauth): """ gets the league id Argument: oauth object 'oauth' Return: string 'leagueID' """ myGame = game.Game(oauth,'nfl') # return NFL fantasy game object prettyPrint(vars(myGame)) try: leagueId = myGame.league_ids(2019)[0] # returns 1 element list, 0th element is leagueID string except Exception as e: print(e) print('>> couldn''t get leagueId') leagueId = 0 return leagueId
Usage: league.py <json> <json> The name of the JSON that has bearer token. This can be generated from init_oauth_env.py. """ from docopt import docopt from yahoo_oauth import OAuth2 from yahoo_fantasy_api import league, game if __name__ == '__main__': args = docopt(__doc__, version='1.0') print(args) sc = OAuth2(None, None, from_file=args['<json>']) gm = game.Game(sc, 'mlb') ids = gm.league_ids() print(ids) for lg_id in ids: if lg_id.find("auto") > 0: continue lg = league.League(sc, lg_id) standings = lg.standings() for i, t in zip(range(1, 100), standings): print("{} - {}".format(i, t)) league_id = gm.league_ids(year=2019) print(league_id) lg = gm.to_league(league_id[0]) settings = lg.settings() print(settings)
def get_all_league_ids(self): current_game = game.Game(self.oauth, "nba") league_ids = current_game.league_ids() return league_ids
from yahoo_oauth import OAuth2 from yahoo_fantasy_api import league, game, team sc = OAuth2(None, None, from_file='oauth2.json') gm = game.Game(sc, 'nfl') gm.league_ids(year=2019) lg = gm.to_league('390.l.642807') lg.current_week() lg.teams()
def test_to_league(sc): gm = game.Game(sc, 'mlb') gm.inject_yhandler(mock_yhandler.YHandler()) lg = gm.to_league('370.l.56877') assert (type(lg) is league.League)
import os import json from yahoo_fantasy_api import league, game, team from yahoo_oauth import OAuth2 if not os.path.exists('oauth2.json'): creds = {'consumer_key': 'my_key', 'consumer_secret': 'my_secret'} with open('oauth2.json', "w") as f: f.write(json.dumps(creds)) oauth = OAuth2(None, None, from_file='oauth2.json') gm = game.Game(oauth, 'nhl') ids = gm.league_ids() print(ids) # 53432 lg = league.League(oauth, '396.l.53432') my_team: team.Team = lg.to_team(lg.team_key()) roster = my_team.roster(lg.current_week()) stats = lg.player_stats([roster[0]['player_id']]) pass