Fix SetSearchLive, SetSearchPhotos and SetSearchVideos
This commit is contained in:
parent
b9ae4a1de2
commit
b6887fca9c
3 changed files with 30 additions and 16 deletions
16
README.md
16
README.md
|
|
@ -65,12 +65,22 @@ func main() {
|
|||
|
||||
The search ends if we have 50 tweets.
|
||||
|
||||
### Search tweet in realtime
|
||||
See [Rules and filtering](https://developer.twitter.com/en/docs/tweets/rules-and-filtering/overview/standard-operators) for build standard queries.
|
||||
|
||||
|
||||
#### Search tweet in realtime
|
||||
```golang
|
||||
scraper.SearchLive(true)
|
||||
scraper.SetSearchLive(true)
|
||||
```
|
||||
|
||||
See [Rules and filtering](https://developer.twitter.com/en/docs/tweets/rules-and-filtering/overview/standard-operators) for build standard queries.
|
||||
#### Filter search
|
||||
```golang
|
||||
scraper.SetSearchPhotos(true)
|
||||
```
|
||||
or
|
||||
```golang
|
||||
scraper.SetSearchVideos(true)
|
||||
```
|
||||
|
||||
### Get profile
|
||||
|
||||
|
|
|
|||
21
scraper.go
21
scraper.go
|
|
@ -15,7 +15,8 @@ type Scraper struct {
|
|||
client *http.Client
|
||||
guestToken string
|
||||
includeReplies bool
|
||||
searchMode string
|
||||
liveSearch bool
|
||||
resultFilter string
|
||||
}
|
||||
|
||||
var defaultScraper *Scraper
|
||||
|
|
@ -28,22 +29,22 @@ func New() *Scraper {
|
|||
}
|
||||
|
||||
// SetSearchLive enable/disable realtime search
|
||||
func (s *Scraper) SetSearchLive(srctype bool) *Scraper {
|
||||
if srctype {
|
||||
s.searchMode = "live"
|
||||
}
|
||||
func (s *Scraper) SetSearchLive(b bool) *Scraper {
|
||||
s.liveSearch = b
|
||||
return s
|
||||
}
|
||||
|
||||
// SetSearchLive wrapper for default SetSearchLive
|
||||
func SetSearchLive(srctype bool) *Scraper {
|
||||
return defaultScraper.SetSearchLive(srctype)
|
||||
func SetSearchLive(b bool) *Scraper {
|
||||
return defaultScraper.SetSearchLive(b)
|
||||
}
|
||||
|
||||
// SetSearchPhotos filter search for photos only
|
||||
func (s *Scraper) SetSearchPhotos(srctype bool) *Scraper {
|
||||
if srctype {
|
||||
s.searchMode = "image"
|
||||
s.resultFilter = "image"
|
||||
} else {
|
||||
s.resultFilter = ""
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
|
@ -56,7 +57,9 @@ func SetSearchPhotos(srctype bool) *Scraper {
|
|||
// SetSearchVideos filter search for videos only
|
||||
func (s *Scraper) SetSearchVideos(srctype bool) *Scraper {
|
||||
if srctype {
|
||||
s.searchMode = "video"
|
||||
s.resultFilter = "video"
|
||||
} else {
|
||||
s.resultFilter = ""
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,10 +37,11 @@ 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)
|
||||
if s.liveSearch {
|
||||
q.Add("tweet_search_mode", "live")
|
||||
}
|
||||
if s.resultFilter != "" {
|
||||
q.Add("result_filter", s.resultFilter)
|
||||
}
|
||||
|
||||
req.URL.RawQuery = q.Encode()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue