예제 #1
0
        private static void GetChallengeCourses(string banapassId, RevScraperClient client)
        {
            Console.WriteLine("Getting courses...");
            IReadOnlyCollection <Uri> courseUris = client.GetCourseUris();

            Console.WriteLine($"Got {courseUris.Count} courses.");

            List <ChallengeCourse> challengeCourses = new List <ChallengeCourse>(courseUris.Count);

            int i = 1;

            foreach (Uri courseUri in courseUris)
            {
                Console.WriteLine($"Getting course {i} of {courseUris.Count}...");
                challengeCourses.Add(client.GetChallengeCourse(courseUri));
                i++;
            }

            string challengeCoursesFilename = string.Format(CultureInfo.InvariantCulture, ChallengeCoursesFilenamePattern, banapassId);

            Console.WriteLine($"Writing scores to {challengeCoursesFilename}...");

            using (FileStream stream = File.Open(challengeCoursesFilename, FileMode.Create))
            {
                using (StreamWriter streamWriter = new StreamWriter(stream, Encoding.UTF8))
                {
                    ChallengeCourse.SerializeHeadersToCSV(streamWriter);

                    foreach (ChallengeCourse challengeCourse in challengeCourses)
                    {
                        challengeCourse.SerializeToCSV(streamWriter);
                    }
                }
            }
        }
예제 #2
0
        public ChallengeCourse GetChallengeCourse(Uri uri)
        {
            string id             = _idRegex.Match(uri.ToString()).Groups[1].Value;
            string responseString = DownloadString(uri);

            HtmlDocument document = new HtmlDocument();

            document.LoadHtml(responseString);

            HtmlNode        challengeCourseElement = document.DocumentNode.SelectNodes("//div[contains(@class, 'pdBlock')]")[0];
            ChallengeCourse challengeCourse        = ChallengeCourse.ParseFromElement(challengeCourseElement, id);

            HtmlNodeCollection songs = document.DocumentNode.SelectNodes("//div[contains(@class, 'chMissionBlock')]");

            foreach (HtmlNode songElement in songs)
            {
                ChallengeSongScore song = ChallengeSongScore.ParseFromElement(songElement);
                challengeCourse.Scores.Add(song);
            }

            return(challengeCourse);
        }
예제 #3
0
        public static ChallengeCourse ParseFromElement(HtmlNode element, string id)
        {
            ChallengeCourse course = new ChallengeCourse();

            course.Id = id;

            course.Name      = HtmlEntity.DeEntitize(element.ChildNodes[1].ChildNodes[1].ChildNodes[3].InnerText.Trim());
            course.MaxCombo  = int.Parse(element.ChildNodes[5].ChildNodes[3].ChildNodes[0].InnerText.Trim());
            course.Score     = int.Parse(element.ChildNodes[7].ChildNodes[3].ChildNodes[0].InnerText.Trim());
            course.ClearRate = decimal.Parse(element.ChildNodes[9].ChildNodes[3].ChildNodes[0].InnerText.Trim().TrimEnd('%'));
            decimal rankPoint;

            if (decimal.TryParse(element.ChildNodes[11].ChildNodes[3].ChildNodes[0].InnerText.Trim(), out rankPoint))
            {
                course.RankPoint = rankPoint;
            }
            else
            {
                course.RankPoint = 0;
            }

            return(course);
        }