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 get_current_league(self): all_league_ids = self.get_all_league_ids() if not all_league_ids: return None league_id = all_league_ids[len(all_league_ids) - 1] current_league = league.League(self.oauth, league_id) return current_league
def to_league(self, league_id): """Construct a League object from a Game :param league_id: League ID of the new League to construct :type league_id: str :return: Fully constructed object :rtype: League """ lg = league.League(self.sc, league_id) lg.inject_yhandler(self.yhandler) return lg
def mock_league(sc): lg = league.League(sc, '370.l.56877') lg.inject_yhandler(mock_yhandler.YHandler()) yield lg
""" 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) print(lg.team_key()) print("Current Week = {}".format(lg.current_week())) print("Ending Week = {}".format(lg.end_week())) print(lg.week_date_range(12))
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
#!/bin/python """Use the team API Usage: team.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, team if __name__ == '__main__': args = docopt(__doc__, version='1.0') print(args) sc = OAuth2(None, None, from_file=args['<json>']) gm = game.Game(sc, 'mlb') league_id = gm.league_ids(year=2019) lg = league.League(sc, league_id[0]) team_key = lg.team_key() tm = team.Team(sc, team_key) print(tm.matchup(3)) print(tm.roster(4))