Beispiel #1
0
        public static List <DoubanHouseInfo> GetDataFromAPI(string groupID, string cityName, int pageIndex)
        {
            List <DoubanHouseInfo> lstHouseInfo = new List <DoubanHouseInfo>();
            var apiURL      = $"https://api.douban.com/v2/group/{groupID}/topics?start={pageIndex * 50}";
            var doubanTopic = WebAPIHelper.GetAPIResult <DoubanTopic>(apiURL);

            if (doubanTopic != null && doubanTopic.topics != null)
            {
                foreach (var topic in doubanTopic.topics)
                {
                    if (DataContent.DoubanHouseInfos.Any(h => h.HouseOnlineURL == topic.share_url))
                    {
                        continue;
                    }
                    var housePrice = JiebaTools.GetHousePrice(topic.content);
                    var house      = new DoubanHouseInfo()
                    {
                        HouseLocation    = topic.title,
                        HouseTitle       = topic.title,
                        HouseOnlineURL   = topic.share_url,
                        HouseText        = topic.content,
                        HousePrice       = JiebaTools.GetHousePrice(topic.content),
                        IsAnalyzed       = true,
                        DisPlayPrice     = housePrice > 0 ? $"{housePrice}元" : "",
                        Source           = ConstConfigurationName.Douban,
                        LocationCityName = cityName,
                        Status           = 1,
                        PubTime          = DateTime.Parse(topic.created),
                        DataCreateTime   = DateTime.Now,
                    };
                    lstHouseInfo.Add(house);
                }
            }
            return(lstHouseInfo);
        }
        public static List <DoubanHouseInfo> GetHouseData(string groupID, string cityName, int pageIndex)
        {
            List <DoubanHouseInfo> lstHouseInfo = new List <DoubanHouseInfo>();
            var apiURL = $"https://api.douban.com/v2/group/{groupID}/topics?start={pageIndex * 50}";
            //LogHelper.Info($"url:{apiURL},groupID:{groupID}, city:{cityName}");
            var result = GetAPIResult(apiURL);

            if (string.IsNullOrEmpty(result))
            {
                return(lstHouseInfo);
            }
            var resultJObject = JsonConvert.DeserializeObject <JObject>(result);

            foreach (var topic in resultJObject["topics"])
            {
                var house = new DoubanHouseInfo()
                {
                    HouseLocation    = topic["title"].ToString(),
                    HouseTitle       = topic["title"].ToString(),
                    HouseOnlineURL   = topic["share_url"].ToString(),
                    HouseText        = topic["content"].ToString(),
                    IsAnalyzed       = true,
                    Source           = ConstConfigurationName.Douban,
                    LocationCityName = cityName,
                    Status           = 1,
                    PubTime          = topic["created"].ToObject <DateTime>(),
                    DataCreateTime   = DateTime.Now,
                };
                lstHouseInfo.Add(house);
            }

            return(lstHouseInfo);
        }