Merge branch 'master' into user-name
This commit is contained in:
commit
d7b7a8754a
3 changed files with 38 additions and 0 deletions
13
timeline.go
13
timeline.go
|
|
@ -27,6 +27,11 @@ type timeline struct {
|
||||||
ExpandedURL string `json:"expanded_url"`
|
ExpandedURL string `json:"expanded_url"`
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
} `json:"urls"`
|
} `json:"urls"`
|
||||||
|
UserMentions []struct {
|
||||||
|
IDStr string `json:"id_str"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
ScreenName string `json:"screen_name"`
|
||||||
|
} `json:"user_mentions"`
|
||||||
} `json:"entities"`
|
} `json:"entities"`
|
||||||
ExtendedEntities struct {
|
ExtendedEntities struct {
|
||||||
Media []struct {
|
Media []struct {
|
||||||
|
|
@ -202,6 +207,14 @@ func (timeline *timeline) parseTweet(id string) *Tweet {
|
||||||
tw.Hashtags = append(tw.Hashtags, hash.Text)
|
tw.Hashtags = append(tw.Hashtags, hash.Text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, mention := range tweet.Entities.UserMentions {
|
||||||
|
tw.Mentions = append(tw.Mentions, Mention{
|
||||||
|
ID: mention.IDStr,
|
||||||
|
Username: mention.ScreenName,
|
||||||
|
Name: mention.Name,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
for _, media := range tweet.ExtendedEntities.Media {
|
for _, media := range tweet.ExtendedEntities.Media {
|
||||||
if media.Type == "photo" {
|
if media.Type == "photo" {
|
||||||
photo := Photo{
|
photo := Photo{
|
||||||
|
|
|
||||||
|
|
@ -100,6 +100,23 @@ func TestGetTweet(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTweetMentions(t *testing.T) {
|
||||||
|
sample := []twitterscraper.Mention{{
|
||||||
|
ID: "7018222",
|
||||||
|
Username: "davidmcraney",
|
||||||
|
Name: "David McRaney",
|
||||||
|
}}
|
||||||
|
scraper := twitterscraper.New()
|
||||||
|
tweet, err := scraper.GetTweet("1554522888904101890")
|
||||||
|
if err != nil {
|
||||||
|
t.Error(err)
|
||||||
|
} else {
|
||||||
|
if diff := cmp.Diff(sample, tweet.Mentions, cmpOptions...); diff != "" {
|
||||||
|
t.Error("Resulting tweet does not match the sample", diff)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestQuotedAndReply(t *testing.T) {
|
func TestQuotedAndReply(t *testing.T) {
|
||||||
sample := &twitterscraper.Tweet{
|
sample := &twitterscraper.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>",
|
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>",
|
||||||
|
|
|
||||||
8
types.go
8
types.go
|
|
@ -3,6 +3,13 @@ package twitterscraper
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
// Mention type.
|
||||||
|
Mention struct {
|
||||||
|
ID string
|
||||||
|
Username string
|
||||||
|
Name string
|
||||||
|
}
|
||||||
|
|
||||||
// Photo type.
|
// Photo type.
|
||||||
Photo struct {
|
Photo struct {
|
||||||
ID string
|
ID string
|
||||||
|
|
@ -28,6 +35,7 @@ type (
|
||||||
IsRetweet bool
|
IsRetweet bool
|
||||||
Likes int
|
Likes int
|
||||||
Name string
|
Name string
|
||||||
|
Mentions []Mention
|
||||||
PermanentURL string
|
PermanentURL string
|
||||||
Photos []Photo
|
Photos []Photo
|
||||||
Place *Place
|
Place *Place
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue