Add optional delay between API requests
This commit is contained in:
parent
1c3fd0e0c9
commit
01ac1b672c
3 changed files with 33 additions and 0 deletions
14
scraper.go
14
scraper.go
|
|
@ -7,16 +7,19 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Scraper object
|
||||
type Scraper struct {
|
||||
client *http.Client
|
||||
delay int64
|
||||
guestToken string
|
||||
guestCreatedAt time.Time
|
||||
includeReplies bool
|
||||
searchMode SearchMode
|
||||
wg sync.WaitGroup
|
||||
}
|
||||
|
||||
// SearchMode type
|
||||
|
|
@ -55,6 +58,17 @@ func SetSearchMode(mode SearchMode) *Scraper {
|
|||
return defaultScraper.SetSearchMode(mode)
|
||||
}
|
||||
|
||||
// WithDelay add delay between API requests (in seconds)
|
||||
func (s *Scraper) WithDelay(seconds int64) *Scraper {
|
||||
s.delay = seconds
|
||||
return s
|
||||
}
|
||||
|
||||
// WithDelay wrapper for default Scraper
|
||||
func WithDelay(seconds int64) *Scraper {
|
||||
return defaultScraper.WithDelay(seconds)
|
||||
}
|
||||
|
||||
// WithReplies enable/disable load timeline with tweet replies
|
||||
func (s *Scraper) WithReplies(b bool) *Scraper {
|
||||
s.includeReplies = b
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue