Пример #1
0
        private static void GetIds()
        {
            const string clansToIdFile = @"C:\Projects\wotclans\GetAllClanIds\ClansToId.txt";

            string[] clansTags = File.ReadAllLines(clansToIdFile, Encoding.UTF8).Select(s => s.Trim())
                                 .Where(s => !string.IsNullOrWhiteSpace(s)).ToArray();
            List <string> ids = new List <string>();

            using (HttpClient client = new HttpClient())
            {
                foreach (string tag in clansTags)
                {
                    string urlRequest =
                        $"https://api-xbox-console.worldoftanks.com/wotx/clans/list/?application_id=demo&search={tag}&limit=1&fields=clan_id%2Ctag";
                    HttpResponseMessage result    = client.GetAsync(urlRequest).Result;
                    string         json           = result.Content.ReadAsStringAsync().Result;
                    ClanInfoResult clanInfoResult = JsonConvert.DeserializeObject <ClanInfoResult>(json);
                    if (clanInfoResult.Status == "ok" && clanInfoResult.Meta.Count == 1 &&
                        clanInfoResult.Data[0].Tag == tag)
                    {
                        ids.Add($"{tag}\t{clanInfoResult.Data[0].ClanId}");
                    }
                }
            }

            const string resultFile = @"C:\Projects\wotclans\GetAllClanIds\ClansIds.txt";

            File.Delete(resultFile);
            File.AppendAllLines(resultFile, ids, Encoding.UTF8);
        }
Пример #2
0
        /// <summary>
        ///     Obtem todos os clas do jogo
        /// </summary>
        private static void GetAllClans()
        {
            List <string> ids = new List <string>();

            using (HttpClient client = new HttpClient())
            {
                // Numero de Páginas a serem lidas
                int lastSize = 100;
                for (int i = 1; i <= 62 && lastSize >= 7; ++i)
                {
                    Console.WriteLine("Consultando página {0}...", i);

                    string urlRequest =
                        $"https://api-xbox-console.worldoftanks.com/wotx/clans/list/?application_id=demo&fields=clan_id%2Ctag%2Cname%2Cmembers_count&page_no={i}";
                    HttpResponseMessage result    = client.GetAsync(urlRequest).Result;
                    string         json           = result.Content.ReadAsStringAsync().Result;
                    ClanInfoResult clanInfoResult = JsonConvert.DeserializeObject <ClanInfoResult>(json);
                    if (clanInfoResult.Status == "ok" && clanInfoResult.Meta.Count >= 1)
                    {
                        foreach (ClanInfo c in clanInfoResult.Data)
                        {
                            ids.Add($"{c.Tag}\t{c.Name}\t{c.ClanId}\t{c.MembersCount}");
                            Console.WriteLine($"    {c.Tag} - {c.ClanId} - {c.MembersCount}");
                            lastSize = c.MembersCount;
                        }
                    }
                }
            }

            const string resultFile = @"C:\Projects\wotclans\GetAllClanIds\AllClans.txt";

            File.Delete(resultFile);
            File.AppendAllLines(resultFile, ids, Encoding.UTF8);
        }