diff --git a/tweets.go b/tweets.go index fc1a9f4..f7cc8fd 100644 --- a/tweets.go +++ b/tweets.go @@ -35,6 +35,8 @@ type Tweet struct { TimeParsed time.Time Timestamp int64 URLs []string + UserID string + Username string Videos []Video } @@ -135,8 +137,9 @@ func readTweetsFromHTML(htm *strings.Reader) ([]*Tweet, error) { tweet.Timestamp, _ = strconv.ParseInt(timeStr, 10, 64) tweet.TimeParsed = time.Unix(tweet.Timestamp, 0) tweet.ID = s.AttrOr("data-item-id", "") - user, _ := s.Find(".tweet").Attr("data-screen-name") - tweet.PermanentURL = fmt.Sprintf("https://twitter.com/%s/status/%s", user, tweet.ID) + tweet.UserID = s.Find(".tweet").AttrOr("data-user-id", "") + tweet.Username = s.Find(".tweet").AttrOr("data-screen-name", "") + tweet.PermanentURL = fmt.Sprintf("https://twitter.com/%s/status/%s", tweet.Username, tweet.ID) tweet.Text = s.Find(".tweet-text").Text() tweet.HTML, _ = s.Find(".tweet-text").Html() s.Find(".js-retweet-text, .QuoteTweet").Each(func(i int, c *goquery.Selection) { diff --git a/tweets_test.go b/tweets_test.go index fd2ed51..3a6c856 100644 --- a/tweets_test.go +++ b/tweets_test.go @@ -19,6 +19,12 @@ func TestGetTweets(t *testing.T) { if tweet.ID == "" { t.Error("Expected tweet ID is not empty") } + if tweet.UserID == "" { + t.Error("Expected tweet UserID is not empty") + } + if tweet.Username == "" { + t.Error("Expected tweet Username is not empty") + } if tweet.PermanentURL == "" { t.Error("Expected tweet PermanentURL is not empty") }