def test_teams(requests_mock): sub_resource = 'teams' path = f'league/nhl.l.123456/{sub_resource}' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, sub_resource) hasattr(api.league().teams().get(), sub_resource)
def test_transactions_empty(requests_mock): sub_resource = 'transactions' path = f'league/nhl.l.123456/{sub_resource}' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, 'transactions_empty') hasattr(api.league().transactions().get(), sub_resource)
def test_settings_nfl(requests_mock): sub_resource = 'settings' path = f'league/nhl.l.123456/{sub_resource}' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, 'settings_nfl') hasattr(api.league().settings().get(), sub_resource)
def test_roster_with_stats_week(requests_mock): sub_resource = 'roster' path = f'team/nhl.l.123456.t.1/{sub_resource};week=1/players/stats' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, 'roster_with_stats') hasattr(api.team(1).roster(week=1).stats().get(), 'roster')
def test_draft_results(requests_mock): sub_resource = 'draftresults' path = f'league/nhl.l.123456/{sub_resource}/players' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, sub_resource) hasattr(api.league().draft_results().get(), sub_resource)
def test_roster_positions(requests_mock): sub_resource = 'roster_positions' path = f'game/nhl/{sub_resource}' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, sub_resource) hasattr(api.game().roster_positions().get(), sub_resource)
def test_roster_week(requests_mock): sub_resource = 'roster' path = f'team/nhl.l.123456.t.1/{sub_resource};week=1' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, sub_resource) hasattr(api.team(1).roster(week=1).get(), sub_resource)
def test_stats(requests_mock): sub_resource = 'stats' path = f'team/nhl.l.123456.t.1/{sub_resource}' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, sub_resource) hasattr(api.team(1).stats().get(), sub_resource)
def test_stat_categories(requests_mock): sub_resource = 'stat_categories' path = f'game/nhl/{sub_resource}' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, sub_resource) hasattr(api.game().stat_categories().get(), sub_resource)
def test_scoreboard_nfl(requests_mock): sub_resource = 'scoreboard' path = f'league/nhl.l.123456/{sub_resource};week=1' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, 'scoreboard_nfl') hasattr(api.league().scoreboard(week=1).get(), sub_resource)
def test_matchups(requests_mock): sub_resource = 'matchups' path = f'team/nhl.l.123456.t.1/{sub_resource};weeks=1' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, sub_resource) hasattr(api.team(1).matchups(week=1).get(), sub_resource)
def test_teams(requests_mock): sub_resource = 'teams' path = 'users;use_login=1/teams' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, sub_resource) hasattr(api.user().teams().get(), sub_resource)
def test_roster_date(requests_mock): sub_resource = 'roster' path = f'team/nhl.l.123456.t.1/{sub_resource};date=2021-03-01' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, sub_resource) hasattr(api.team(1).roster(date='2021-03-01').get(), sub_resource)
def test_players(requests_mock): sub_resource = 'players' path = f'league/nhl.l.123456/{sub_resource};search=search;status=K' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, sub_resource) hasattr(api.league().players(search='search', status='K').get(), sub_resource)
def test_transactions_waiver(requests_mock): sub_resource = 'transactions' path = f'league/nhl.l.123456/{sub_resource};type=waiver;team_key=nhl.l.123456.t.1;count=1;start=1' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, sub_resource) hasattr( api.league().transactions(ttype='waiver', team_id=1, count=1, start=1).get(), sub_resource)
def test_meta(requests_mock): path = 'league/nhl.l.123456' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, 'meta') hasattr(api.league().meta().get(), 'league_id')
def test_meta(requests_mock): path = 'team/nhl.l.123456.t.1' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, 'meta') hasattr(api.team(1).meta().get(), 'info')
from yfantasy_api.api import YahooFantasyApi from keeper_website.app import db, create_app from datetime import timedelta, datetime from sqlalchemy import func from keeper_website.models import Team, Player, PlayerStats, GoalieStats, SelectedPositions, \ Draft, Pick, Transaction, TransactionPicks, TransactonPlayers from keeper_website.utils.date_utils import get_date_range, get_todays_date from flask import Flask import os app = create_app() app.app_context().push() print(db) yfs = YahooFantasyApi(league_id=17457) def update_teams(): teams = yfs.get_league_teams() for t in teams: if t == 'count': continue team = Team.parse_json(teams[t]['team'][0]) db.session.merge(team) db.session.commit() def update_players(): keeper_costs = get_keeper_cost() for i in range(0, 2500, 25):
from yfantasy_api.api import YahooFantasyApi league_id = 17457 # This should be the id of the league you are querying game_id = 'nhl' # This should be the id of the game you are querying team_id = 1 # This should be the id of the team you are querying api = YahooFantasyApi(league_id, game_id) def example_usage_one(): team = api \ .team(team_id) \ .roster() \ .stats(date='2021-03-31') \ .get() for player in team.players: print(player.full_name, player.points) def example_usage_two(): league = api \ .league() \ .draft_results() \ .players() \ .get() for draft_result in league.draft_results: print( f'{draft_result.round} - {draft_result.pick} - {draft_result.player.full_name}' )
def test_meta(requests_mock): path = 'users;user_login=1' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, 'meta') hasattr(api.user().meta().get(), 'guid')
from yfantasy_api.api import YahooFantasyApi from utils.date_utils import get_todays_date import argparse import csv import itertools TEAM_MAP = {} yfs = YahooFantasyApi(league_id=5194) parser = argparse.ArgumentParser() parser.add_argument('-d', '--debug', action='store_true', default=False, help='Output useful debug information') args = parser.parse_args() def __get_draft_costs(): """Get drafted player keeper costs using the Yahoo Fantasy API. Return a map of player ids to their keeper costs. """ draft_picks = yfs.get_draft_results() keeper_costs = {} for d in draft_picks: if d == 'count': continue draft_pick = draft_picks[d]['draft_result'] player_id = draft_pick['player_key'][6:] cost = draft_pick['round'] - 1
def test_players_with_stats_more_than_one_coverage(requests_mock): api = YahooFantasyApi(123456, 'nhl', timeout=0) with raises(Exception) as sys_exit_e: api.league().players().stats(date='2021-03-01', season=2020).get() assert sys_exit_e.type == Exception
def test_players_with_stats_filter_week(requests_mock): path = 'league/nhl.l.123456/players;start=0;count=25/stats;week=1' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, 'players_with_stats') hasattr(api.league().players().stats(week=1).get(), 'players')
def test_players_with_percent_owned(requests_mock): path = 'league/nhl.l.123456/players;start=0;count=25/percent_owned' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, 'players_with_percent_owned') hasattr(api.league().players().percent_owned().get(), 'players')
def test_players_with_draft_analysis(requests_mock): path = 'league/nhl.l.123456/players;start=0;count=25/draft_analysis' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, 'players_with_draft_analysis') hasattr(api.league().players().draft_analysis().get(), 'players')
def test_roster_with_more_than_one_coverage(requests_mock): api = YahooFantasyApi(123456, 'nhl', timeout=0) with raises(Exception) as sys_exit_e: api.team(1).roster(date='2021-03-01', week=1).get() assert sys_exit_e.type == Exception
def test_games(requests_mock): api = YahooFantasyApi(123456, 'nhl', timeout=0) path = 'games;is_available=1;game_codes=nhl;seasons=2020' mock_request(requests_mock, path, 'games') api.games().get(is_available=True, game_codes=['nhl'], seasons=[2020])
def test_game_old(requests_mock): path = 'game/nhl' api = YahooFantasyApi(123456, 'nhl', timeout=0) mock_request(requests_mock, path, 'old') hasattr(api.game().get(), 'game_key')
def test_transactions_waiver_missing_team(): api = YahooFantasyApi(123456, 'nhl', timeout=0) with raises(Exception) as sys_exit_e: api.league().transactions(ttype='waiver').get() assert sys_exit_e.type == Exception