Parse a retweet like a full tweet

This commit is contained in:
Alexander Sheiko 2021-07-16 11:37:43 +03:00
parent 34aae0d008
commit c370a9078f
3 changed files with 14 additions and 19 deletions

View file

@ -173,18 +173,7 @@ func (timeline *timeline) parseTweet(id string) *Tweet {
} }
if tweet.RetweetedStatusIDStr != "" { if tweet.RetweetedStatusIDStr != "" {
tw.IsRetweet = true tw.IsRetweet = true
if retweet, ok := timeline.GlobalObjects.Tweets[tweet.RetweetedStatusIDStr]; ok { tw.Retweet = timeline.parseTweet(tweet.RetweetedStatusIDStr)
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()
}
}
} }
for _, pinned := range timeline.GlobalObjects.Users[tweet.UserIDStr].PinnedTweetIdsStr { for _, pinned := range timeline.GlobalObjects.Users[tweet.UserIDStr].PinnedTweetIdsStr {

View file

@ -96,12 +96,18 @@ func TestGetTweet(t *testing.T) {
} }
func TestRetweet(t *testing.T) { func TestRetweet(t *testing.T) {
sample := Retweet{ sample := &Tweet{
ID: "1359151057872580612", HTML: "Weve seen an increase in attacks against Asian communities and individuals around the world. Its important to know that this isnt 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)), ID: "1359151057872580612",
Timestamp: 1612881838, Likes: 6683,
UserID: "773578328498372608", PermanentURL: "https://twitter.com/TwitterTogether/status/1359151057872580612",
Username: "TwitterTogether", Replies: 455,
Retweets: 1495,
Text: "Weve seen an increase in attacks against Asian communities and individuals around the world. Its important to know that this isnt 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") tweet, err := defaultScraper.GetTweet("1362849141248974853")
if err != nil { if err != nil {

View file

@ -33,7 +33,7 @@ type (
Photos []string Photos []string
Replies int Replies int
Retweets int Retweets int
Retweet Retweet Retweet *Tweet
Text string Text string
TimeParsed time.Time TimeParsed time.Time
Timestamp int64 Timestamp int64