add SearchLive SearchPhotos SearchVideos

This commit is contained in:
JustHumanz 2020-12-20 00:20:27 +07:00
parent c9ba00cad7
commit 7363f676bf
3 changed files with 51 additions and 0 deletions

View file

@ -65,6 +65,11 @@ func main() {
The search ends if we have 50 tweets.
### Search tweet in realtime
```golang
scraper.SearchLive(true)
```
See [Rules and filtering](https://developer.twitter.com/en/docs/tweets/rules-and-filtering/overview/standard-operators) for build standard queries.
### Get profile

View file

@ -15,6 +15,7 @@ type Scraper struct {
client *http.Client
guestToken string
includeReplies bool
searchMode string
}
var defaultScraper *Scraper
@ -26,6 +27,45 @@ func New() *Scraper {
}
}
// SetSearchLive enable/disable realtime search
func (s *Scraper) SearchLive(srctype bool) *Scraper {
if srctype {
s.searchMode = "live"
}
return s
}
// SetSearchLive wrapper for default SetSearchLive
func SearchLive(srctype bool) *Scraper {
return defaultScraper.SearchLive(srctype)
}
// SetSearchPhotos filter search for photos only
func (s *Scraper) SearchPhotos(srctype bool) *Scraper {
if srctype {
s.searchMode = "image"
}
return s
}
// SetSearchPhotos wrapper for default SetSearchPhotos
func SearchPhotos(srctype bool) *Scraper {
return defaultScraper.SearchPhotos(srctype)
}
// SetSearchVideos filter search for videos only
func (s *Scraper) SearchVideos(srctype bool) *Scraper {
if srctype {
s.searchMode = "video"
}
return s
}
// SetSearchVideos wrapper for default SetSearchVideos
func SearchVideos(srctype bool) *Scraper {
return defaultScraper.SearchVideos(srctype)
}
// WithReplies enable/disable load timeline with tweet replies
func (s *Scraper) WithReplies(b bool) *Scraper {
s.includeReplies = b

View file

@ -37,6 +37,12 @@ func (s *Scraper) FetchSearchTweets(query string, maxTweetsNbr int, cursor strin
if cursor != "" {
q.Add("cursor", cursor)
}
if s.searchMode == "live" {
q.Add("tweet_search_mode", s.searchMode)
} else {
q.Add("result_filter", s.searchMode)
}
req.URL.RawQuery = q.Encode()
var timeline timeline