示例#1
0
        private static async Task <BaseResponce <List <DictionaryData> > > GetDictsAsync()
        {
            //var handler = new HttpClientHandler() { UseProxy = false };
            var url = $"https://iasdnpp.mos.ru/dnpp_map/api/dictionaries/?access_token={Token}";
            var res = await ReqController.SendRequestAsync(ReqType.GET, url);

            if (res.Response == null)
            {
                return(null);
            }
            return(JsonConvert.DeserializeObject <BaseResponce <List <DictionaryData> > >(res.Response));
        }
示例#2
0
        private static async Task <BaseResponce <Datum> > GetObjDataAsync(int objId)
        {
            //var handler = new HttpClientHandler() { UseProxy = false };
            var url = $"https://iasdnpp.mos.ru/dnpp_map/api/inno-objects/{objId}/?&access_token={Token}";
            var res = await ReqController.SendRequestAsync(ReqType.GET, url);

            if (res.Response == null)
            {
                return(null);
            }
            return(JsonConvert.DeserializeObject <BaseResponce <Datum> >(res.Response));
        }
示例#3
0
        private static async Task <List <FormatSpace> > GetFormatspacesAsync(int objId)
        {
            //var handler = new HttpClientHandler() { UseProxy = false };
            var url = $"http://imoscow.mos.ru/ru/infrastructure/object/detail/{objId}/formatspaces";

            if ((DateTime.Now - LastPageReqDate).TotalSeconds < 1)
            {
                await Task.Delay(TimeSpan.FromSeconds(1));
            }
            var res = await ReqController.SendRequestAsync(ReqType.GET, url);

            LastPageReqDate = DateTime.Now;
            //
            if (res.Response == null)
            {
                return(null);
            }

            var parser      = new HtmlParser();
            var document    = parser.Parse(res.Response);
            var spacesNames = document.QuerySelectorAll(".expanding-blocks__item");
            var spacesDecs  = document.QuerySelectorAll(".expanding-blocks__descr");

            var result = new List <FormatSpace>();

            for (var i = 0; i < spacesNames.Length; i++)
            {
                if (spacesDecs.Length <= i)
                {
                    break;
                }
                var desc = spacesDecs[i];

                var descDict = spacesDecs[i].QuerySelectorAll("dl")
                               .Select(x =>
                {
                    var val = x.GetElementsByTagName("dd").FirstOrDefault();
                    return(new
                    {
                        key = x.GetElementsByTagName("dt").FirstOrDefault()?.InnerHtml?.ToLower(),
                        value = val?.InnerHtml ??
                                ""     // val != null && !val.HasChildNodes ? (object)val.InnerHtml : val.ChildNodes.Select(c => c.Text()).ToArray(),
                    });
                })
                               .Where(x => !string.IsNullOrWhiteSpace(x.key))
                               .GroupBy(x => x.key)
                               .ToDictionary(x => x.Key, y => y.First().value);

                var spaceInfo = new FormatSpace
                {
                    Name        = spacesNames[i].QuerySelector(".spaces__descr")?.InnerHtml,
                    Description = descDict.ContainsKey("описание") ? descDict["описание"]?.ToString() : null,
                    ImgUrl      = spacesDecs[i].QuerySelector(".img-fluid")?.GetAttribute("src"),
                    Price       = descDict.ContainsKey("стоимость (руб.)") ? descDict["стоимость (руб.)"] as string : null,
                    SpaceCount  = descDict.ContainsKey("количество мест") ? descDict["количество мест"] as string : null,
                    //Worksheet = descDict.ContainsKey("рабочие дни") ? descDict["рабочие дни"] as List<string> : null,
                };
                result.Add(spaceInfo);
            }

            return(result);
        }