add check for maxTweetsNbr and rename GetSearchTweets fun to Search Tweets
This commit is contained in:
parent
9c16b10725
commit
9497edf199
2 changed files with 7 additions and 6 deletions
|
|
@ -9,8 +9,8 @@ import (
|
||||||
|
|
||||||
const ajaxSearchURL = "https://twitter.com/i/search/timeline?q=%s"
|
const ajaxSearchURL = "https://twitter.com/i/search/timeline?q=%s"
|
||||||
|
|
||||||
// GetTweets returns channel with tweets for a given search query
|
// SearchTweets returns channel with tweets for a given search query
|
||||||
func GetSearchTweets(query string, maxTweetsNbr int) <-chan *Result {
|
func SearchTweets(query string, maxTweetsNbr int) <-chan *Result {
|
||||||
channel := make(chan *Result)
|
channel := make(chan *Result)
|
||||||
go func(query string) {
|
go func(query string) {
|
||||||
defer close(channel)
|
defer close(channel)
|
||||||
|
|
@ -40,7 +40,7 @@ func GetSearchTweets(query string, maxTweetsNbr int) <-chan *Result {
|
||||||
return channel
|
return channel
|
||||||
}
|
}
|
||||||
|
|
||||||
// FetchTweets gets tweets for a given search query, via the Twitter frontend API
|
// FetchSearchTweets gets tweets for a given search query, via the Twitter frontend API
|
||||||
func FetchSearchTweets(query, maxId string) ([]*Tweet, error) {
|
func FetchSearchTweets(query, maxId string) ([]*Tweet, error) {
|
||||||
if maxId != "" {
|
if maxId != "" {
|
||||||
query = query + " max_id:" + maxId
|
query = query + " max_id:" + maxId
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ import "testing"
|
||||||
|
|
||||||
func TestGetSearchTweets(t *testing.T) {
|
func TestGetSearchTweets(t *testing.T) {
|
||||||
count := 0
|
count := 0
|
||||||
for tweet := range GetSearchTweets("twitter scraper data -filter:retweets", 50) {
|
maxTweetsNbr := 50
|
||||||
|
for tweet := range SearchTweets("twitter scraper data -filter:retweets", maxTweetsNbr) {
|
||||||
if tweet.Error != nil {
|
if tweet.Error != nil {
|
||||||
t.Error(tweet.Error)
|
t.Error(tweet.Error)
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -30,7 +31,7 @@ func TestGetSearchTweets(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if count == 0 {
|
if count != maxTweetsNbr {
|
||||||
t.Error("Expected tweets count is greater than zero")
|
t.Errorf("Expected tweets count=%v, got: %v", maxTweetsNbr, count)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue