コード例 #1
0
        // nba_id = 364
        //FantasyContent content = Client.ExecuteRequest<FantasyContent>("http://fantasysports.yahooapis.com/fantasy/v2/game/nba");

        //content = Client.ExecuteRequest<FantasyContent>("http://fantasysports.yahooapis.com/fantasy/v2/league/364.l.45575");

        //content = Client.ExecuteRequest<FantasyContent>("http://fantasysports.yahooapis.com/fantasy/v2/team/364.l.45575.t.2/roster/players");

        //content = Client.ExecuteRequest<FantasyContent>("http://fantasysports.yahooapis.com/fantasy/v2/player/364.p.4612/stats");

        private static FantasyTeam GetTeam(string leagueId, string teamId)
        {
            FantasyTeam team = new FantasyTeam();

            string         teamUrl     = "http://fantasysports.yahooapis.com/fantasy/v2/team/364.l." + leagueId + ".t." + teamId + "/roster/players";
            FantasyContent teamContent = Client.ExecuteRequest <FantasyContent>(teamUrl);

            team.Id      = teamContent.Team.Id;
            team.Manager = teamContent.Team.Managers[0].Nickname;
            team.Name    = teamContent.Team.Name;

            foreach (Team.Roster.TeamPlayer item in teamContent.Team.TeamRoster.Players)
            {
                FantasyPlayer player = new FantasyPlayer();
                player.Id   = item.Id;
                player.Name = item.Name.Full;

                string         playerUrl     = "http://fantasysports.yahooapis.com/fantasy/v2/player/364.p." + player.Id + "/stats";
                FantasyContent playerContent = Client.ExecuteRequest <FantasyContent>(playerUrl);

                player.SeasonStats = new FantasyStats(playerContent.Player.PlayerStatistics.Stats);
                team.Players.Add(player);
            }

            return(team);
        }
コード例 #2
0
        private static List <FantasyTeam> GetLeague(bool useCache)
        {
            if (useCache)
            {
                if (File.Exists(CACHE_FILE))
                {
                    using (StreamReader file = File.OpenText(CACHE_FILE))
                    {
                        JsonSerializer     serializer  = new JsonSerializer();
                        List <FantasyTeam> cacheLeague = (List <FantasyTeam>)serializer.Deserialize(file, typeof(List <FantasyTeam>));
                        return(cacheLeague);
                    }
                }
            }

            FantasyContent leagueContent = Client.ExecuteRequest <FantasyContent>("http://fantasysports.yahooapis.com/fantasy/v2/league/364.l.45575");
            int            numTeams      = int.Parse(leagueContent.League.NumTeams);

            List <FantasyTeam> league = new List <FantasyTeam>();

            for (int i = 1; i < (numTeams + 1); i++)
            {
                try
                {
                    FantasyTeam team = GetTeam("45575", i.ToString());
                    Thread.Sleep(3000);
                    league.Add(team);
                }
                catch (Exception)
                {
                }
            }

            using (StreamWriter file = File.CreateText(CACHE_FILE))
            {
                JsonSerializer serializer = new JsonSerializer();
                serializer.Serialize(file, league);
            }

            return(league);
        }