-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a blocked service; interval is every 15 minutes
- Loading branch information
Showing
6 changed files
with
258 additions
and
130 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/dghubble/go-twitter/twitter" | ||
"github.com/dghubble/oauth1" | ||
) | ||
|
||
type TwitterAPIAuthentication struct { | ||
*twitter.Client | ||
} | ||
|
||
func newTwitterAPIAuthentication(params OAuth1AuthenticationParameters) *TwitterAPIAuthentication { | ||
config := oauth1.NewConfig(params.ConsumerKey, params.ConsumerSecret) | ||
httpClient := config.Client(oauth1.NoContext, oauth1.NewToken(params.AccessKey, params.AccessSecret)) | ||
client := twitter.NewClient(httpClient) | ||
if client == nil { | ||
return nil | ||
} | ||
return &TwitterAPIAuthentication{client} | ||
} | ||
|
||
// Stream tweets based on terms e.g. a hashtag. | ||
func (a *TwitterAPIAuthentication) MustStream(terms []string) <-chan *twitter.Tweet { | ||
params := &twitter.StreamFilterParams{Track: terms} | ||
ch, err := a.Streams.Filter(params) | ||
if err != nil { | ||
panic(err) | ||
} | ||
out := make(chan *twitter.Tweet) | ||
go func() { | ||
defer func() { ch.Stop(); close(out) }() | ||
for msg := range ch.Messages { | ||
tweet, ok := msg.(*twitter.Tweet) | ||
if !ok { | ||
log.Printf("(error) msg.(*twitter.Tweet): tweet=%+v", tweet) | ||
continue | ||
} else if tweet.RetweetedStatus != nil { // Ignore RTs | ||
// No-op | ||
continue | ||
} | ||
out <- tweet | ||
} | ||
}() | ||
return out | ||
} | ||
|
||
func (t *TwitterAPIAuthentication) Retweet(tweet *twitter.Tweet) error { | ||
if tweet.Retweeted { | ||
return nil | ||
} | ||
_, _, err := t.Statuses.Retweet(tweet.ID, nil) | ||
return err | ||
} | ||
|
||
func (a *TwitterAPIAuthentication) Like(tweet *twitter.Tweet) error { | ||
if tweet.Favorited { | ||
return nil | ||
} | ||
params := &twitter.FavoriteCreateParams{ID: tweet.ID} | ||
_, _, err := a.Favorites.Create(params) | ||
return err | ||
} | ||
|
||
func (a *TwitterAPIAuthentication) Follow(tweet *twitter.Tweet) error { | ||
if tweet.User.Following { | ||
return nil | ||
} | ||
params := &twitter.FriendshipCreateParams{UserID: tweet.User.ID} | ||
_, _, err := a.Friendships.Create(params) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.