Add InReplyToStatus, QuotedStatus and RetweetedStatus parsing in Tweet
BREAKING CHANGE: Retweet property renamed to RetweetedStatus Closed #41
This commit is contained in:
parent
c370a9078f
commit
be2c3ec5b1
3 changed files with 60 additions and 22 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -95,6 +95,40 @@ func TestGetTweet(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestQuotedAndReply(t *testing.T) {
|
||||
sample := &Tweet{
|
||||
HTML: "The Easiest Problem Everyone Gets Wrong <br><br>[new video] --> <a href=\"https://youtu.be/ytfCdqWhmdg\">https://t.co/YdaeDYmPAU</a> <br><a href=\"https://t.co/iKu4Xs6o2V\"><img src=\"https://pbs.twimg.com/media/ESsZa9AXgAIAYnF.jpg\"/></a>",
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
4
types.go
4
types.go
|
|
@ -24,6 +24,7 @@ type (
|
|||
Hashtags []string
|
||||
HTML string
|
||||
ID string
|
||||
InReplyToStatus *Tweet
|
||||
IsQuoted bool
|
||||
IsPin bool
|
||||
IsReply bool
|
||||
|
|
@ -31,9 +32,10 @@ type (
|
|||
Likes int
|
||||
PermanentURL string
|
||||
Photos []string
|
||||
QuotedStatus *Tweet
|
||||
Replies int
|
||||
Retweets int
|
||||
Retweet *Tweet
|
||||
RetweetedStatus *Tweet
|
||||
Text string
|
||||
TimeParsed time.Time
|
||||
Timestamp int64
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue