Parse a retweet like a full tweet
This commit is contained in:
parent
34aae0d008
commit
c370a9078f
3 changed files with 14 additions and 19 deletions
13
timeline.go
13
timeline.go
|
|
@ -173,18 +173,7 @@ func (timeline *timeline) parseTweet(id string) *Tweet {
|
|||
}
|
||||
if tweet.RetweetedStatusIDStr != "" {
|
||||
tw.IsRetweet = true
|
||||
if retweet, ok := timeline.GlobalObjects.Tweets[tweet.RetweetedStatusIDStr]; ok {
|
||||
tw.Retweet = Retweet{
|
||||
ID: tweet.RetweetedStatusIDStr,
|
||||
UserID: retweet.UserIDStr,
|
||||
Username: timeline.GlobalObjects.Users[retweet.UserIDStr].ScreenName,
|
||||
}
|
||||
tm, err := time.Parse(time.RubyDate, retweet.CreatedAt)
|
||||
if err == nil {
|
||||
tw.Retweet.TimeParsed = tm
|
||||
tw.Retweet.Timestamp = tm.Unix()
|
||||
}
|
||||
}
|
||||
tw.Retweet = timeline.parseTweet(tweet.RetweetedStatusIDStr)
|
||||
}
|
||||
|
||||
for _, pinned := range timeline.GlobalObjects.Users[tweet.UserIDStr].PinnedTweetIdsStr {
|
||||
|
|
|
|||
|
|
@ -96,12 +96,18 @@ func TestGetTweet(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestRetweet(t *testing.T) {
|
||||
sample := Retweet{
|
||||
ID: "1359151057872580612",
|
||||
TimeParsed: time.Date(2021, 02, 9, 14, 43, 58, 0, time.FixedZone("UTC", 0)),
|
||||
Timestamp: 1612881838,
|
||||
UserID: "773578328498372608",
|
||||
Username: "TwitterTogether",
|
||||
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.",
|
||||
ID: "1359151057872580612",
|
||||
Likes: 6683,
|
||||
PermanentURL: "https://twitter.com/TwitterTogether/status/1359151057872580612",
|
||||
Replies: 455,
|
||||
Retweets: 1495,
|
||||
Text: "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.",
|
||||
TimeParsed: time.Date(2021, 02, 9, 14, 43, 58, 0, time.FixedZone("UTC", 0)),
|
||||
Timestamp: 1612881838,
|
||||
UserID: "773578328498372608",
|
||||
Username: "TwitterTogether",
|
||||
}
|
||||
tweet, err := defaultScraper.GetTweet("1362849141248974853")
|
||||
if err != nil {
|
||||
|
|
|
|||
2
types.go
2
types.go
|
|
@ -33,7 +33,7 @@ type (
|
|||
Photos []string
|
||||
Replies int
|
||||
Retweets int
|
||||
Retweet Retweet
|
||||
Retweet *Tweet
|
||||
Text string
|
||||
TimeParsed time.Time
|
||||
Timestamp int64
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue