Add Scraper object
This commit is contained in:
parent
edad8f6393
commit
6bf65cd482
9 changed files with 158 additions and 80 deletions
15
tweets.go
15
tweets.go
|
|
@ -6,22 +6,27 @@ import (
|
|||
)
|
||||
|
||||
// GetTweets returns channel with tweets for a given user.
|
||||
func (s *Scraper) GetTweets(ctx context.Context, user string, maxTweetsNbr int) <-chan *Result {
|
||||
return getTimeline(ctx, user, maxTweetsNbr, s.FetchTweets)
|
||||
}
|
||||
|
||||
// GetTweets wrapper for default Scraper
|
||||
func GetTweets(ctx context.Context, user string, maxTweetsNbr int) <-chan *Result {
|
||||
return getTimeline(ctx, user, maxTweetsNbr, FetchTweets)
|
||||
return defaultScraper.GetTweets(ctx, user, maxTweetsNbr)
|
||||
}
|
||||
|
||||
// FetchTweets gets tweets for a given user, via the Twitter frontend API.
|
||||
func FetchTweets(user string, maxTweetsNbr int, cursor string) ([]*Tweet, string, error) {
|
||||
func (s *Scraper) FetchTweets(user string, maxTweetsNbr int, cursor string) ([]*Tweet, string, error) {
|
||||
if maxTweetsNbr > 200 {
|
||||
maxTweetsNbr = 200
|
||||
}
|
||||
|
||||
userID, err := GetUserIDByScreenName(user)
|
||||
userID, err := s.GetUserIDByScreenName(user)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
req, err := newRequest("GET", "https://api.twitter.com/2/timeline/profile/"+userID+".json")
|
||||
req, err := s.newRequest("GET", "https://api.twitter.com/2/timeline/profile/"+userID+".json")
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
|
@ -35,7 +40,7 @@ func FetchTweets(user string, maxTweetsNbr int, cursor string) ([]*Tweet, string
|
|||
req.URL.RawQuery = q.Encode()
|
||||
|
||||
var timeline timeline
|
||||
err = requestAPI(req, &timeline)
|
||||
err = s.RequestAPI(req, &timeline)
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue