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);
            }
        }
Esempio n. 2
0
        private static List <EmbedFieldBuilder> BuildFields(GeneralPost display)
        {
            List <EmbedFieldBuilder> embedFields = new List <EmbedFieldBuilder>();

            embedFields.Add(new EmbedFieldBuilder()
            {
                IsInline = true, Name = "Author name", Value = display.Author
            });

            if (display.AuthorFlair != null && display.AuthorFlair.Trim().Length != 0)
            {
                embedFields.Add(new EmbedFieldBuilder()
                {
                    IsInline = false, Name = "Author flair", Value = display.AuthorFlair
                });
            }

            embedFields.Add(new EmbedFieldBuilder()
            {
                IsInline = true, Name = "Created", Value = display.Created.ToShortDateString()
            });

            if (display.PostFlair != null && display.PostFlair.Trim().Length != 0)
            {
                embedFields.Add(new EmbedFieldBuilder()
                {
                    IsInline = false, Name = "Post flair", Value = display.PostFlair
                });
            }

            if (display.Title != null && display.Title.Trim().Length != 0)
            {
                embedFields.Add(new EmbedFieldBuilder()
                {
                    IsInline = false, Name = "Post Title", Value = display.Title
                });
            }

            return(embedFields);
        }
Esempio n. 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);
            }
        }
Esempio n. 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);
            }
        }