~alexwennerberg/twitterbots-go

8f2feedc27c9e829e621b588fb7dbf19e8ebe38e — alex wennerberg 25 days ago f38d7f1
Add logging and noop flag
1 files changed, 9 insertions(+), 4 deletions(-)

M main.go
M main.go => main.go +9 -4
@@ 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
}