public SearchResult Search(string query)
        {
            SearchResult searchResult = new SearchResult();

            searchResult.Query = HttpUtility.UrlEncode(query);

            Cenzor cenzor = new Cenzor();

            if (query != cenzor.Cenz(query, dict))
            {
                return(searchResult);
            }

            InstagramSearch instagram = new InstagramSearch();
            VKSearch        vk        = new VKSearch();
            TwitterSearch   twitter   = new TwitterSearch();

            instThread    = new Thread(() => searchResult.InstPagination = instagram.Search(query, searchResult.Posts, "", dict));
            vkThread      = new Thread(() => searchResult.VKPagination = vk.Search(query, searchResult.Posts, "", dict));
            twitterThread = new Thread(() => searchResult.TwitterPagination = twitter.Search(query, searchResult.Posts, "", dict));

            instThread.Start();
            vkThread.Start();
            twitterThread.Start();
            instThread.Join();
            vkThread.Join();
            twitterThread.Join();

            searchResult.Posts = searchResult.Posts.OrderByDescending(p => p.Date).ToList();

            return(searchResult);
        }
        private void PostSearch(IElement item, List <string> dict)
        {
            GeneralPost tweet = new GeneralPost();
            var         h     = item.QuerySelectorAll("div").Where(k => k.ClassName.Contains("AdaptiveMediaOuterContainer"));

            if (!(h.Count() == 0))
            {
                if (h.First().QuerySelectorAll("img").Count() != 0)
                {
                    tweet.Image = h.First().QuerySelectorAll("img").First().Attributes["src"].Value;
                }
            }
            long id = long.Parse(item.Attributes["data-item-id"].Value);

            tweet.Text = item.QuerySelectorAll("p").Where(k => k.ClassName.Contains("tweet-text")).First().InnerHtml;

            Cenzor cenzor = new Cenzor();

            tweet.Text = cenzor.Cenz(tweet.Text, dict);

            tweet.Social     = SocialMedia.Twitter;
            tweet.AuthorName = item.QuerySelectorAll("div").Where(k => k.ClassName.Contains("tweet")).First().Attributes["data-name"].Value;
            string linkname = item.QuerySelectorAll("div").Where(k => k.ClassName.Contains("tweet")).First().Attributes["data-screen-name"].Value;

            tweet.PostLink     = "https://twitter.com/" + linkname + "/status/" + id;
            tweet.AuthorLink   = "https://twitter.com/" + linkname;
            tweet.AuthorAvatar = item.QuerySelectorAll("img").Where(y => y.ClassName.Contains("avatar")).First().Attributes["src"].Value;
            try
            {
                var elemwithdate    = item.QuerySelectorAll("div").Where(k => k.ClassName.Contains("content")).First().QuerySelectorAll("div").Where(o => o.ClassName.Contains("stream-item-header")).First().QuerySelectorAll("small").Where(u => u.ClassName.Contains("time")).First().QuerySelectorAll("a").Where(f => f.ClassName.Contains("tweet-timestamp")).First().Attributes["title"].Value;
                var massivstrdate   = elemwithdate.Split('-');
                var massivyearmohtn = massivstrdate[1].Split(' ');
                var h1 = massivstrdate[0].TrimEnd(' ');
                var h2 = massivyearmohtn[1];
                var h3 = massivyearmohtn[2];
                var h4 = massivyearmohtn[3];
                var d  = item.QuerySelectorAll("div").Where(k => k.ClassName.Contains("content")).First().QuerySelectorAll("div").Where(o => o.ClassName.Contains("stream-item-header")).First().QuerySelectorAll("small").Where(u => u.ClassName.Contains("time")).First().QuerySelectorAll("a").Where(f => f.ClassName.Contains("tweet-timestamp")).First().QuerySelectorAll("span").Where(p => p.ClassName.Contains("_timestamp")).First().Attributes["data-time-ms"].Value;
                var s1 = h1.Split(':');
                tweet.Date = (new DateTime(Int32.Parse(h4), getMonth(h3), Int32.Parse(h2), Int32.Parse(s1[0]), Int32.Parse(s1[1]), 0));
            }
            catch {
            }
            AngleSharp.Parser.Html.HtmlParser parser       = new AngleSharp.Parser.Html.HtmlParser();
            AngleSharp.Dom.Html.IHtmlDocument htmldocument = parser.Parse(tweet.Text);

            var links = htmldocument.QuerySelectorAll("a");

            foreach (var link in links)
            {
                tweet.Text = tweet.Text.Replace(link.OuterHtml, link.InnerHtml);
            }



            lock (posts)
            {
                posts.Add(tweet);
            }
        }
示例#3
0
        private void PostSearch(dynamic instagramPost, List <GeneralPost> searchResult, List <string> dict)
        {
            GeneralPost newPost = new GeneralPost();

            newPost.Text = instagramPost.caption;

            Cenzor cenzor = new Cenzor();

            newPost.Text = cenzor.Cenz(newPost.Text, dict);

            newPost.Image = instagramPost.display_src;
            double sec = instagramPost.date;

            newPost.Date     = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(sec).ToLocalTime();
            newPost.PostLink = "https://www.instagram.com/p/" + instagramPost.code;
            newPost.Social   = SocialMedia.Instagram;

            try
            {
                var request        = (HttpWebRequest)WebRequest.Create(newPost.PostLink + "/?__a=1");
                var response       = (HttpWebResponse)request.GetResponse();
                var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();

                dynamic instPostData = JsonConvert.DeserializeObject(responseString);
                var     instAuthor   = instPostData.graphql.shortcode_media.owner;

                newPost.AuthorName   = instAuthor.username;
                newPost.AuthorLink   = "https://www.instagram.com/" + newPost.AuthorName;
                newPost.AuthorAvatar = instAuthor.profile_pic_url;
            }
            catch { }

            lock (searchResult)
            {
                searchResult.Add(newPost);
            }
        }
示例#4
0
        private void PostSearch(dynamic vkPost, List <GeneralPost> searchResult, List <string> dict)
        {
            GeneralPost newPost = new GeneralPost();

            newPost.Text = vkPost.text;
            try
            {
                newPost.Text += Environment.NewLine + vkPost.copy_history.text;
            }
            catch { }

            Cenzor cenzor = new Cenzor();

            newPost.Text = cenzor.Cenz(newPost.Text, dict);

            while (true)
            {
                int begin = newPost.Text.IndexOf("[");
                if (begin == -1)
                {
                    break;
                }
                int end = newPost.Text.IndexOf("]");
                if (end == -1 || end < begin)
                {
                    break;
                }
                string nameFull = newPost.Text.Substring(begin, end - begin + 1);
                int    vert     = nameFull.IndexOf("|");
                if (vert == -1)
                {
                    break;
                }
                string name = nameFull.Substring(vert + 1, nameFull.Length - vert - 2);
                newPost.Text = newPost.Text.Replace(nameFull, name);
            }

            newPost.Social = SocialMedia.VK;

            double sec = vkPost.date;

            newPost.Date = (new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).AddSeconds(sec).ToLocalTime();

            try
            {
                foreach (var att in vkPost.attachments)
                {
                    string type = att.type;
                    string source;
                    if (type == "video")
                    {
                        source = att.video.photo_800;
                        if (source != null)
                        {
                            newPost.Image = source; break;
                        }
                        source = att.video.photo_640;
                        if (source != null)
                        {
                            newPost.Image = source; break;
                        }
                    }
                    else if (type == "photo")
                    {
                        source = att.photo.photo_807;
                        if (source != null)
                        {
                            newPost.Image = source; break;
                        }
                        source = att.photo.photo_604;
                        if (source != null)
                        {
                            newPost.Image = source; break;
                        }
                        break;
                    }
                }
            }
            catch { }

            int fromID = vkPost.from_id;

            string screenName = authors[fromID].ScreenName;

            newPost.AuthorName   = authors[fromID].Name;
            newPost.AuthorAvatar = authors[fromID].Photo;

            string ownerID = vkPost.owner_id;
            string ID      = vkPost.id;

            newPost.PostLink   = "https://vk.com/" + screenName + "?w=wall" + ownerID + "_" + ID;
            newPost.AuthorLink = "https://vk.com/" + screenName;
            lock (searchResult)
            {
                searchResult.Add(newPost);
            }
        }