Skip to content

Commit

Permalink
feat(tweet): set the hashtag through command line args
Browse files Browse the repository at this point in the history
  • Loading branch information
bdeneux committed Nov 25, 2022
1 parent 7143033 commit 9ad11d1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
6 changes: 3 additions & 3 deletions app/actor/tweet/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ type SearchActor struct {
Context context.Context
}

func NewSearchActor(eventStore *actor.PID, mongoURI, dbName, tweeterToken string) (*SearchActor, error) {
func NewSearchActor(eventStore *actor.PID, mongoURI, dbName, tweeterToken, hashtag string) (*SearchActor, error) {
ctx := context.Background()
store, err := offset.NewStore(ctx, mongoURI, dbName, ownerOffset)
if err != nil {
return nil, err
}

return &SearchActor{
Hashtag: "#NemetonOKP4 -is:retweet",
Hashtag: hashtag,
TweeterToken: tweeterToken,
Client: http.DefaultClient,
EventStore: eventStore,
Expand Down Expand Up @@ -109,7 +109,7 @@ func (a *SearchActor) fetchTweets(sinceID, nextToken string) (*Response, error)
return nil, err
}
query := u.Query()
query.Add("query", a.Hashtag)
query.Add("query", fmt.Sprintf("%s -is:retweet", a.Hashtag))
query.Add("expansions", "author_id")
query.Add("user.fields", "username")

Expand Down
10 changes: 6 additions & 4 deletions app/system/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ type App struct {
init *actor.PID
}

func Bootstrap(listenAddr, mongoURI, dbName, grpcAddr, tweeterToken string, tls credentials.TransportCredentials) *App {
func Bootstrap(listenAddr, mongoURI, dbName, grpcAddr, tweeterToken, hashtag string, tls credentials.TransportCredentials) *App {
initProps := actor.PropsFromFunc(func(ctx actor.Context) {
if _, ok := ctx.Message().(*actor.Started); ok {
boot(ctx, listenAddr, mongoURI, dbName, grpcAddr, tweeterToken, tls)
boot(ctx, listenAddr, mongoURI, dbName, grpcAddr, tweeterToken, hashtag, tls)
}
})

Expand All @@ -40,7 +40,9 @@ func (app *App) Stop() error {
return app.ctx.StopFuture(app.init).Wait()
}

func boot(ctx actor.Context, listenAddr, mongoURI, dbName, grpcAddr, tweeterToken string, tls credentials.TransportCredentials) {
func boot(ctx actor.Context, listenAddr, mongoURI, dbName, grpcAddr, tweeterToken, hashtag string,
tls credentials.TransportCredentials,
) {
grpcClientProps := actor.PropsFromProducer(func() actor.Actor {
grpcClient, err := cosmos.NewGrpcClient(grpcAddr, tls)
if err != nil {
Expand Down Expand Up @@ -70,7 +72,7 @@ func boot(ctx actor.Context, listenAddr, mongoURI, dbName, grpcAddr, tweeterToke
}

tweetProps := actor.PropsFromProducer(func() actor.Actor {
actor, err := tweet.NewSearchActor(eventStorePID, mongoURI, dbName, tweeterToken)
actor, err := tweet.NewSearchActor(eventStorePID, mongoURI, dbName, tweeterToken, hashtag)
if err != nil {
log.Panic().Err(err).Msg("❌ Could not start tweet actor")
}
Expand Down
22 changes: 14 additions & 8 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,24 @@ const (
FlagNoTLS = "no-tls"
FlagTLSSkipVerify = "tls-skip-verify"
FlagTweeterToken = "tweeter-token" // nolint:gosec
FlagTweeterHashtag = "tweeter-hashtag"
)

var (
graphqlAddr string
mongoURI string
dbName string
grpcAddress string
noTLS bool
tlsSkipVerify bool
tweeterToken string
graphqlAddr string
mongoURI string
dbName string
grpcAddress string
noTLS bool
tlsSkipVerify bool
tweeterToken string
tweeterHashtag string

startCmd = &cobra.Command{
Use: "start",
Short: "Start the leaderboard service",
Run: func(cmd *cobra.Command, args []string) {
app := system.Bootstrap(graphqlAddr, mongoURI, dbName, grpcAddress, tweeterToken, getTransportCredentials())
app := system.Bootstrap(graphqlAddr, mongoURI, dbName, grpcAddress, tweeterToken, tweeterHashtag, getTransportCredentials())

kill := make(chan os.Signal, 1)
signal.Notify(kill, syscall.SIGINT, syscall.SIGTERM)
Expand All @@ -64,6 +66,10 @@ func init() {
false,
"Encryption with the GRPC endpoint but skip certificates verification")
startCmd.PersistentFlags().StringVar(&tweeterToken, FlagTweeterToken, "", "Set the tweeter bearer token")
startCmd.PersistentFlags().StringVar(&tweeterHashtag,
FlagTweeterHashtag,
"#NemetonOKP4",
"Set the tweeter hashtag that will stream all tweet")
}

func getTransportCredentials() credentials.TransportCredentials {
Expand Down

0 comments on commit 9ad11d1

Please sign in to comment.