Пример #1
0
        private async Task LoadSchedule()
        {
            using var httpClient = new HttpClient();
            //TODO: Hard-coded week count, if there was a non-paginated version that'd be nice.
            foreach (int page in Enumerable.Range(1, 27))
            {
                botMethods.Log(this, new LogEventArgs {
                    Type    = LogType.Log,
                    Message = $"OverwatchLeague is requesting the schedule for week {page}"
                });
                var    uri     = new Uri($"https://wzavfvwgfk.execute-api.us-east-2.amazonaws.com/production/owl/paginator/schedule?stage=regular_season&page={page}&season=2020&locale=en-us");
                string referer = "https://overwatchleague.com/en-us/schedule";
                using var getMessage = new HttpRequestMessage {
                          Method     = HttpMethod.Get,
                          RequestUri = uri
                      };
                getMessage.Headers.Add("Referer", referer);
                var getResponse = await httpClient.SendAsync(getMessage);

                var getResponseString = await getResponse.Content.ReadAsStringAsync();

                dynamic getResponseJson = JsonConvert.DeserializeObject(getResponseString);

                int    weekNumber = (int)getResponseJson.content.tableData.weekNumber.Value;
                string weekName   = getResponseJson.content.tableData.name;

                var week = new Week(weekNumber, weekName);
                foreach (var weekEvent in getResponseJson.content.tableData.events)
                {
                    string eventTitle = "Venue to be decided";                     //TODO: Week 10 is the first event where this is the case; the website seems to not list a venue either.
                    try {
                        eventTitle = weekEvent.eventBanner.title;
                    } catch (RuntimeBinderException) { }
                    var e = new Event(eventTitle);
                    e.SetWeek(week);
                    week.AddEvent(e);

                    foreach (var match in weekEvent.matches)
                    {
                        int matchId   = (int)match.id;
                        var homeTeam  = teams.Single(t => t.Id == (int)match.competitors[0].id.Value);
                        var awayTeam  = teams.Single(t => t.Id == (int)match.competitors[1].id.Value);
                        int homeScore = 0;
                        int awayScore = 0;
                        if (match.scores.Count > 0)
                        {
                            homeScore = (int)match.scores[0];
                            awayScore = (int)match.scores[1];
                        }
                        string   status    = match.status;
                        DateTime startTime = new DateTime(1970, 1, 1, 0, 0, 0).AddMilliseconds((double)match.startDate);
                        DateTime endTime   = new DateTime(1970, 1, 1, 0, 0, 0).AddMilliseconds((double)match.endDate);
                        //TODO: Get the actual start and end times (do they not exist anymore?).
                        // Maps are added only when requested since they must be gotten on a per-match basis.
                        var m = new Match(botMethods, matchId, homeTeam, awayTeam, homeScore, awayScore, status, startTime, endTime, null, null);
                        m.SetEvent(e);
                        matches.Add(m);
                        homeTeam.AddMatch(m);
                        awayTeam.AddMatch(m);
                        e.AddMatch(m);
                    }
                }

                weeks.Add(week);
            }
        }
Пример #2
0
 public void SetWeek(Week week)
 {
     Week = week;
 }