Use search GraphQL API

Close #109 #116
This commit is contained in:
Alexander Sheiko 2023-07-03 14:38:46 +03:00
parent 07ad3789ef
commit 391e443058
5 changed files with 329 additions and 204 deletions

View file

@ -2,18 +2,23 @@ package twitterscraper_test
import (
"context"
"os"
"testing"
twitterscraper "github.com/n0madic/twitter-scraper"
)
var searchScraper = twitterscraper.New()
func TestFetchSearchCursor(t *testing.T) {
err := searchScraper.LoginOpenAccount()
if os.Getenv("SKIP_AUTH_TEST") != "" {
t.Skip("Skipping test due to environment variable")
}
searchScraper := twitterscraper.New()
err := searchScraper.Login(username, password)
if err != nil {
t.Fatal(err)
}
defer searchScraper.Logout()
maxTweetsNbr := 150
tweetsNbr := 0
nextCursor := ""
@ -31,13 +36,19 @@ func TestFetchSearchCursor(t *testing.T) {
}
func TestGetSearchProfiles(t *testing.T) {
if os.Getenv("SKIP_AUTH_TEST") != "" {
t.Skip("Skipping test due to environment variable")
}
count := 0
maxProfilesNbr := 150
dupcheck := make(map[string]bool)
err := searchScraper.LoginOpenAccount()
searchScraper := twitterscraper.New()
err := searchScraper.Login(username, password)
if err != nil {
t.Fatal(err)
}
defer searchScraper.Logout()
searchScraper.SetSearchMode(twitterscraper.SearchUsers)
for profile := range searchScraper.SearchProfiles(context.Background(), "Twitter", maxProfilesNbr) {
if profile.Error != nil {
@ -61,13 +72,19 @@ func TestGetSearchProfiles(t *testing.T) {
}
}
func TestGetSearchTweets(t *testing.T) {
if os.Getenv("SKIP_AUTH_TEST") != "" {
t.Skip("Skipping test due to environment variable")
}
count := 0
maxTweetsNbr := 150
dupcheck := make(map[string]bool)
err := searchScraper.LoginOpenAccount()
searchScraper := twitterscraper.New()
err := searchScraper.Login(username, password)
if err != nil {
t.Fatal(err)
}
defer searchScraper.Logout()
searchScraper.SetSearchMode(twitterscraper.SearchLatest)
for tweet := range searchScraper.SearchTweets(context.Background(), "twitter", maxTweetsNbr) {
if tweet.Error != nil {