Пример #1
0
        private async Task populateScore(CodewarsUser user)
        {
            WebClient client      = new WebClient();
            string    apiResponse = null;

            try
            {
                apiResponse = await client.DownloadStringTaskAsync("https://www.codewars.com/api/v1/users/" + user.Username);
            }
            catch
            {
                Console.WriteLine("Error getting a user's data from Codewars: " + user.Username);
                user.Score = -1;
                user.TotalCompletedKata = -1;
            }

            if (apiResponse != null)
            {
                JObject response = JObject.Parse(apiResponse);
                int.TryParse(response.GetValue("honor").ToString(), out int score);
                int.TryParse(response.SelectToken("codeChallenges.totalCompleted").ToString(), out int totalCompletedKataCount);
                user.Score = score;
                user.TotalCompletedKata = totalCompletedKataCount;
            }
        }
Пример #2
0
        public CodewarsUsersGroup(string file)
        {
            Users = new List <CodewarsUser>();

            string[,] data = new DataFinder().ReadCsvFile(file, "Unable to read usernames file.", true);

            if (data == null)
            {
                return;
            }

            for (int row = 0; row < data.GetLength(0); row++)
            {
                CodewarsUser newUser = new CodewarsUser(data[row, 0]);
                newUser.Name = data[row, 1].Length > 0 ? data[row, 1] : "[No Name]";
                Users.Add(newUser);
            }
        }