Exemplo n.º 1
0
        public static TwitterSchema Parse(this TwitterTimelineItem item)
        {
            TwitterSchema tweet = new TwitterSchema
            {
                _id              = item.Id,
                Text             = item.Text.DecodeHtml(),
                CreationDateTime = TryParse(item.CreatedAt)
            };

            if (item.User == null)
            {
                tweet.UserId              = string.Empty;
                tweet.UserName            = string.Empty;
                tweet.UserScreenName      = string.Empty;
                tweet.UserProfileImageUrl = string.Empty;
                tweet.Url = string.Empty;
            }
            else
            {
                tweet.UserId              = item.User.Id;
                tweet.UserName            = item.User.Name.DecodeHtml();
                tweet.UserScreenName      = string.Concat("@", item.User.ScreenName.DecodeHtml());
                tweet.UserProfileImageUrl = item.User.ProfileImageUrl;
                tweet.Url = string.Format("https://twitter.com/{0}/status/{1}", item.User.ScreenName, item.Id);
                if (!string.IsNullOrEmpty(tweet.UserProfileImageUrl))
                {
                    tweet.UserProfileImageUrl = tweet.UserProfileImageUrl.Replace("_normal", string.Empty);
                }
            }

            return(tweet);
        }
Exemplo n.º 2
0
        private static void FillUserData(ref TwitterSchema tweet, TwitterTimelineItem item)
        {
            TwitterUser user = null;

            if (item.RetweetedStatus != null)
            {
                user           = item.RetweetedStatus.User;
                tweet.UserName = $"{item.RetweetedStatus.User.Name.DecodeHtml()} (RT @{item.User.ScreenName.DecodeHtml()})";
            }
            else if (item.User != null)
            {
                user           = item.User;
                tweet.UserName = item.User.Name.DecodeHtml();
            }

            tweet.UserId              = user.Id;
            tweet.UserScreenName      = string.Concat("@", user.ScreenName.DecodeHtml());
            tweet.UserProfileImageUrl = user.ProfileImageUrl;
            tweet.Url = string.Format("https://twitter.com/{0}/status/{1}", user.ScreenName, item.Id);
            if (!string.IsNullOrEmpty(tweet.UserProfileImageUrl))
            {
                tweet.UserProfileImageUrl = tweet.UserProfileImageUrl.Replace("_normal", string.Empty);
            }

            var text = item.Text;

            if (item.Entities?.Urls?.Count > 0)
            {
                foreach (TwitterUrl url in item.Entities.Urls)
                {
                    // special case where the URL is a Twitter video
                    if (url.DisplayUrl.Contains("amp.twimg.com/v/"))
                    {
                        text = text.Replace(url.Url, string.Empty);
                    }
                    else
                    {
                        text = text.Replace(url.Url, url.DisplayUrl);
                    }
                }
            }

            if (item.Entities?.Media?.Count > 0)
            {
                foreach (TwitterMedia media in item.Entities.Media)
                {
                    text = text.Replace(media.Url, string.Empty);

                    if ((media.Type == "photo") && (tweet.ImageUrl == null))
                    {
                        tweet.ImageUrl = new Uri(media.MediaUrl);
                    }
                }
            }

            // a '\n' could be at thye end of the tweet if we removed a Twitter video
            tweet.Text = text.TrimEnd('\n').DecodeHtml();
        }
Exemplo n.º 3
0
        public static TwitterSchema Parse(this TwitterTimelineItem item)
        {
            TwitterSchema tweet = new TwitterSchema()
            {
                CreationDateTime = TryParse(item.CreatedAt)
            };

            FillUserData(ref tweet, item);
            FillTweet(ref tweet, item);
            return(tweet);
        }
Exemplo n.º 4
0
        public static TwitterSchema Parse(this TwitterTimelineItem item)
        {
            TwitterSchema tweet = new TwitterSchema()
            {
                _id = item.Id
            };

            FillUserData(ref tweet, item);
            FillTweet(ref tweet, item);
            return(tweet);
        }
Exemplo n.º 5
0
 private static void FillTweet(ref TwitterSchema tweet, TwitterTimelineItem item)
 {
     if (item.RetweetedStatus == null)
     {
         tweet.Text = item.Text.DecodeHtml();
     }
     else
     {
         tweet.Text = item.RetweetedStatus.Text.DecodeHtml();
     }
     tweet.CreationDateTime = TryParse(item.CreatedAt);
 }
Exemplo n.º 6
0
        private static void FillUserData(ref TwitterSchema tweet, TwitterTimelineItem item)
        {
            TwitterUser user = null;

            if (item.RetweetedStatus != null)
            {
                user           = item.RetweetedStatus.User;
                tweet.UserName = $"{item.RetweetedStatus.User.Name.DecodeHtml()} (RT @{item.User.ScreenName.DecodeHtml()})";
            }
            else if (item.User != null)
            {
                user           = item.User;
                tweet.UserName = item.User.Name.DecodeHtml();
            }

            tweet.UserId              = user.Id;
            tweet.UserScreenName      = string.Concat("@", user.ScreenName.DecodeHtml());
            tweet.UserProfileImageUrl = user.ProfileImageUrl;
            tweet.Url = string.Format("https://twitter.com/{0}/status/{1}", user.ScreenName, item.Id);
            if (!string.IsNullOrEmpty(tweet.UserProfileImageUrl))
            {
                tweet.UserProfileImageUrl = tweet.UserProfileImageUrl.Replace("_normal", string.Empty);
            }
        }