twitterbots-go

twitter bots @soulstxt and @lacroix-bot
Log | Files | Refs | README | LICENSE

commit 8f2feedc27c9e829e621b588fb7dbf19e8ebe38e
parent f38d7f1af4d03af8e6b1310f9254ff18b9a3a69c
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sun, 27 Sep 2020 10:00:49 -0700

Add logging and noop flag

Diffstat:
Mmain.go | 13+++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/main.go b/main.go @@ -3,9 +3,9 @@ package main import ( "encoding/json" "flag" - "fmt" "github.com/dghubble/go-twitter/twitter" "github.com/dghubble/oauth1" + "log" "math/rand" "os" "time" @@ -15,8 +15,9 @@ func main() { rand.Seed(time.Now().Unix()) fileName := flag.String("config", "", "config filepath") mode := flag.String("mode", "", "mode, either souls or lacroix") + noop := flag.Bool("noop", false, "don't post tweet, just echo") flag.Parse() - fmt.Println("Loading authentication data from", *fileName) + log.Println("Loading authentication data from", *fileName) config, err := loadConfig(fileName) if err != nil { panic(err) @@ -34,11 +35,15 @@ func main() { if err != nil { panic(err) } + if *noop { + log.Println(tweet) + return + } postedTweet, _, err := client.Statuses.Update(tweet, nil) if err != nil { panic(err) } - fmt.Printf("@%s posted update \"%s\"\n", postedTweet.User.ScreenName, tweet) + log.Printf("@%s posted update \"%s\"\n", postedTweet.User.ScreenName, tweet) if err != nil { panic(err) } @@ -77,7 +82,7 @@ func loadConfig(configFilename *string) (*TwitterCreds, error) { configuration := TwitterCreds{} err = decoder.Decode(&configuration) if err != nil { - fmt.Println("error:", err) + return nil, err } return &configuration, nil }