예제 #1
0
        public async Task <IList <Root> > GetScheduleOnNextWeekAsync()
        {
            var scheduleResponse = await client.GetAsync(Links.BaseLink + Links.ScheduleLink);

            if (scheduleResponse.IsSuccessStatusCode)
            {
                var content = await scheduleResponse.Content.ReadAsStringAsync();

                var doc     = parser.ParseDocument(content);
                var element = doc.QuerySelector("script[type='text/javascript']");
                var id      = TextWorker.GetUserId(element.TextContent);

                var weekNumber  = (int)DateTime.Now.DayOfWeek;
                var dataRequest = DateTime.Now;
                if (weekNumber != 0)
                {
                    var weekStart = weekNumber - 1;
                    dataRequest = dataRequest.AddDays(-weekStart);
                }
                else
                {
                    dataRequest = dataRequest.AddDays(-6);
                }
                var jsonShedule = await GetJsonSchedule(id, dataRequest.AddDays(7));

                var schedule = JsonConvert.DeserializeObject <IList <Root> >(jsonShedule);
                return(schedule);
            }
            return(new List <Root>());
        }