Exemple #1
0
        static void SetKeySkillsForVacancy(Vacan vacancy)
        {
            string vacResponse = SendRequest("https://api.hh.ru/", "vacancies/" + vacancy.Id).Result;

            dynamic vacResults = JsonConvert.DeserializeObject <dynamic>(vacResponse);

            if (vacResults.keyskills != null)
            {
                foreach (var keyskill in vacResults.keyskills)
                {
                    vacancy.KeySkills.Add((string)keyskill.name);
                }
            }
        }
Exemple #2
0
        static List <Vacan> GetVacancies()
        {
            Console.WriteLine("Cбор данных...");
            List <Curren> curren = new List <Curren>();

            Console.WriteLine("Курса валют...");
            string  curResponse = SendRequest("https://api.hh.ru/", "dictionaries").Result;
            dynamic curResults  = JsonConvert.DeserializeObject <dynamic>(curResponse);

            if (curResults.currency != null)
            {
                foreach (var cur in curResults.currency)
                {
                    Curren cu = new Curren();
                    if (cur.code != null)
                    {
                        cu.Code = (string)cur.code;
                    }
                    if (cur.rate != null)
                    {
                        cu.Rate = (double)cur.rate;
                    }
                    curren.Add(cu);
                }
            }
            List <Vacan> vaca = new List <Vacan>();

            Console.WriteLine("Получение вакансий...");
            for (int i = 0; i < 20; i++)
            {
                Console.WriteLine("Запрос 20 элементов с " + i + " страницы");
                string  formattedResponse = SendRequest("https://api.hh.ru/", "vacancies?per_page=20&page=" + i).Result;
                dynamic result            = JsonConvert.DeserializeObject <dynamic>(formattedResponse);
                if (result.items != null)
                {
                    foreach (var item in result.items)
                    {
                        if (item.salary != null)
                        {
                            Vacan v = new Vacan();
                            if (item.id != null)
                            {
                                v.Id = (int)item.id;
                            }
                            if (item.name != null)
                            {
                                v.Name = (string)item.name;
                            }

                            if (item.salary.from != null && item.salary.to != null)
                            {
                                v.Salary = ((int)item.salary.from + (int)item.salary.to) / 2;
                            }
                            else if (item.salary.from != null)
                            {
                                v.Salary = (int)item.salary.from;
                            }
                            else if (item.salary.to != null)
                            {
                                v.Salary = (int)item.salary.to;
                            }

                            if (item.salary.currency != null)
                            {
                                v.Salary = (int)(v.Salary * curren.Find(c => c.Code.Equals((string)item.salary.currency)).Rate);
                            }

                            vaca.Add(v);
                        }
                    }
                }
            }
            Console.WriteLine();

            return(vaca);
        }