Add user info in tweet
This commit is contained in:
parent
49baceb5b4
commit
f99c2aaa1f
2 changed files with 11 additions and 2 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue