Пример #1
0
        public List <Dictionary <string, object> > GetTouTiaoSearch(string keyword)
        {
            var list     = new List <Dictionary <string, object> >();
            var htmlList = DataSourceTouTiao.GetInstance().GetSearchResult(keyword);

            if (null != htmlList && 0 < htmlList.Count)
            {
                foreach (var html in htmlList)
                {
                    var resDict  = Convertor.FromJsonToDict2(html);
                    var dataList = resDict["data"] as ArrayList;

                    foreach (Dictionary <string, object> dataItem in dataList)
                    {
                        if (dataItem.ContainsKey("article_url") && dataItem.ContainsKey("title") && dataItem.ContainsKey("abstract") &&
                            dataItem.ContainsKey("create_time") && dataItem.ContainsKey("media_url") && dataItem.ContainsKey("media_avatar_url"))
                        {
                            var url              = dataItem["article_url"].ToString();
                            var source           = dataItem["source"];
                            var media_url        = dataItem["media_url"];
                            var imageUrl         = dataItem.ContainsKey("image_url") ? dataItem["image_url"] : "";
                            var media_avatar_url = dataItem["media_avatar_url"];
                            var title            = dataItem["title"];
                            var summary          = dataItem["abstract"];
                            var createTime       = dataItem["create_time"];
                            if (url.StartsWith("http://toutiao.com/group/"))
                            {
                                var articleString = DataSourceTouTiao.GetInstance().GetArticle(url);
                                if (!string.IsNullOrWhiteSpace(articleString))
                                {
                                    var startIndex = articleString.IndexOf("content:") + "content:".Length;
                                    var endIndex   = articleString.IndexOf("groupId:");
                                    articleString = articleString.Substring(startIndex, endIndex - startIndex);
                                    var item = new Dictionary <string, object> {
                                        { "Title", title }
                                        , { "Summary", summary }
                                        , { "Content", articleString }
                                        , { "ImageUrl", media_avatar_url }
                                        , { "CreateTime", new DateTime(1970, 1, 1).AddSeconds(long.Parse(createTime.ToString())) }
                                        , { "CreatorName", source }
                                        , { "CreatorID", media_url }
                                        , { "CreatorPic", media_avatar_url }
                                    };
                                    list.Add(item);
                                }
                            }
                        }
                    }
                }
            }

            return(list);
        }
Пример #2
0
        public static DataSourceTouTiao GetInstance()
        {
            var inst = new DataSourceTouTiao();

            return(inst);
        }