diff --git a/timeline.go b/timeline.go index 16c3839..0916633 100644 --- a/timeline.go +++ b/timeline.go @@ -167,13 +167,15 @@ func (timeline *timeline) parseTweet(id string) *Tweet { if tweet.QuotedStatusIDStr != "" { tw.IsQuoted = true + tw.QuotedStatus = timeline.parseTweet(tweet.QuotedStatusIDStr) } if tweet.InReplyToStatusIDStr != "" { tw.IsReply = true + tw.InReplyToStatus = timeline.parseTweet(tweet.InReplyToStatusIDStr) } if tweet.RetweetedStatusIDStr != "" { tw.IsRetweet = true - tw.Retweet = timeline.parseTweet(tweet.RetweetedStatusIDStr) + tw.RetweetedStatus = timeline.parseTweet(tweet.RetweetedStatusIDStr) } for _, pinned := range timeline.GlobalObjects.Users[tweet.UserIDStr].PinnedTweetIdsStr { diff --git a/tweets_test.go b/tweets_test.go index 1c313a9..32cca31 100644 --- a/tweets_test.go +++ b/tweets_test.go @@ -95,6 +95,40 @@ func TestGetTweet(t *testing.T) { } } +func TestQuotedAndReply(t *testing.T) { + sample := &Tweet{ + HTML: "The Easiest Problem Everyone Gets Wrong

[new video] --> https://t.co/YdaeDYmPAU
", + ID: "1237110546383724547", + Likes: 484, + PermanentURL: "https://twitter.com/VsauceTwo/status/1237110546383724547", + Photos: []string{"https://pbs.twimg.com/media/ESsZa9AXgAIAYnF.jpg"}, + Replies: 12, + Retweets: 18, + Text: "The Easiest Problem Everyone Gets Wrong \n\n[new video] --> https://t.co/YdaeDYmPAU https://t.co/iKu4Xs6o2V", + TimeParsed: time.Date(2020, 03, 9, 20, 18, 33, 0, time.FixedZone("UTC", 0)), + Timestamp: 1583785113, + URLs: []string{"https://youtu.be/ytfCdqWhmdg"}, + UserID: "978944851", + Username: "VsauceTwo", + } + tweet, err := defaultScraper.GetTweet("1237110897597976576") + if err != nil { + t.Error(err) + } else { + if diff := cmp.Diff(sample, tweet.QuotedStatus); diff != "" { + t.Error("Resulting quote does not match the sample", diff) + } + } + tweet, err = defaultScraper.GetTweet("1237111868445134850") + if err != nil { + t.Error(err) + } else { + if diff := cmp.Diff(sample, tweet.InReplyToStatus); diff != "" { + t.Error("Resulting reply does not match the sample", diff) + } + } + +} func TestRetweet(t *testing.T) { sample := &Tweet{ HTML: "We’ve seen an increase in attacks against Asian communities and individuals around the world. It’s important to know that this isn’t new; throughout history, Asians have experienced violence and exclusion. However, their diverse lived experiences have largely been overlooked.", @@ -113,7 +147,7 @@ func TestRetweet(t *testing.T) { if err != nil { t.Error(err) } else { - if diff := cmp.Diff(sample, tweet.Retweet); diff != "" { + if diff := cmp.Diff(sample, tweet.RetweetedStatus); diff != "" { t.Error("Resulting retweet does not match the sample", diff) } } diff --git a/types.go b/types.go index 5bb0f3e..a4a9084 100644 --- a/types.go +++ b/types.go @@ -21,26 +21,28 @@ type ( // Tweet type. Tweet struct { - Hashtags []string - HTML string - ID string - IsQuoted bool - IsPin bool - IsReply bool - IsRetweet bool - Likes int - PermanentURL string - Photos []string - Replies int - Retweets int - Retweet *Tweet - Text string - TimeParsed time.Time - Timestamp int64 - URLs []string - UserID string - Username string - Videos []Video + Hashtags []string + HTML string + ID string + InReplyToStatus *Tweet + IsQuoted bool + IsPin bool + IsReply bool + IsRetweet bool + Likes int + PermanentURL string + Photos []string + QuotedStatus *Tweet + Replies int + Retweets int + RetweetedStatus *Tweet + Text string + TimeParsed time.Time + Timestamp int64 + URLs []string + UserID string + Username string + Videos []Video } // ProfileResult of scrapping.