Ejemplo n.º 1
0
        private void SearchAndPopulate(List <string> subreddits, string ticker, bool sorting = false, string sort = "relevance")
        {
            // If we are sorting, we have to empty our dictionarys as we getting all new data.
            if (sorting)
            {
                SearchModel.SavedData.PostDict               = new Dictionary <string, List <Post> >();
                SearchModel.SavedData.SubredditImages        = new Dictionary <string, string>();
                SearchModel.SavedData.SubredditColors        = new Dictionary <string, string>();
                SearchModel.SavedData.PostsTimePassedStrings = new Dictionary <Post, Tuple <string, string> >();
            }
            foreach (string sub in subreddits)
            {
                // Get current subreddit from api
                Subreddit currentSubreddit = SearchModel.SavedData.Reddit.Subreddit(name: sub);

                SearchGetSearchInput searchQuery = new SearchGetSearchInput(ticker, sort: sort);
                List <Post>          subPosts    = currentSubreddit.Search(searchQuery);
                SearchModel.SavedData.PostDict.Add(sub, subPosts);

                GetPostsTimePassed(subPosts);


                Subreddit currentSubredditInfo = currentSubreddit.About();

                string dirtyBackgroundImgUrl = currentSubredditInfo.CommunityIcon;
                string backgroundImgUrl;
                if (dirtyBackgroundImgUrl.Contains(".png"))
                {
                    backgroundImgUrl = dirtyBackgroundImgUrl.Substring(0, dirtyBackgroundImgUrl.LastIndexOf(".png") + 4);
                }
                else
                {
                    backgroundImgUrl = dirtyBackgroundImgUrl.Substring(0, dirtyBackgroundImgUrl.LastIndexOf(".jpg") + 4);
                }

                // Add to the subreddit images
                SearchModel.SavedData.SubredditImages.Add(sub, backgroundImgUrl);
                SearchModel.SavedData.SubredditColors.Add(sub, currentSubredditInfo.PrimaryColor);
            }
        }