Merge pull request #19 from JustHumanz/master

add SetSearchLive,SetSearchPhotos, and SetSearchVideos
This commit is contained in:
Nomadic 2020-12-23 18:51:43 +02:00 committed by GitHub
commit b9ae4a1de2
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) SetSearchLive(srctype bool) *Scraper {
if srctype {
s.searchMode = "live"
}
return s
}
// SetSearchLive wrapper for default SetSearchLive
func SetSearchLive(srctype bool) *Scraper {
return defaultScraper.SetSearchLive(srctype)
}
// SetSearchPhotos filter search for photos only
func (s *Scraper) SetSearchPhotos(srctype bool) *Scraper {
if srctype {
s.searchMode = "image"
}
return s
}
// SetSearchPhotos wrapper for default SetSearchPhotos
func SetSearchPhotos(srctype bool) *Scraper {
return defaultScraper.SetSearchPhotos(srctype)
}
// SetSearchVideos filter search for videos only
func (s *Scraper) SetSearchVideos(srctype bool) *Scraper {
if srctype {
s.searchMode = "video"
}
return s
}
// SetSearchVideos wrapper for default SetSearchVideos
func SetSearchVideos(srctype bool) *Scraper {
return defaultScraper.SetSearchVideos(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