~alexwennerberg/twitterbots-go

08507926089a8c2876dc9051c96de934b554e013 — alex wennerberg 2 months ago 54a11b7
finished config, tested tweet from accounts
1 files changed, 24 insertions(+), 3 deletions(-)

M main.go
M main.go => main.go +24 -3
@@ 13,24 13,41 @@ func main() {
	fileName := flag.String("config", "", "config filepath")
	flag.Parse()
	fmt.Println("Loading config from", *fileName)
	client, err := getCreds(fileName)
	fmt.Println("Username:", *fileName)
	config, err := loadConfig(fileName)
	client, err := getTwitterClient(config)
	var tweet string
	if config.Username == "soulstxt" {
		tweet = generateSoulsTweet()
	} else if config.Username == "lacroixbot" {
		tweet = generateLacroixTweet()
	}
	if err != nil {
		panic(err)
	}
	_, _, err = client.Statuses.Update("just setting up my twttr", nil)
	_, _, err = client.Statuses.Update(tweet, nil)
	if err != nil {
		panic(err)
	}
}

func generateLacroixTweet() string {
	return "test flavored la croix"
}

func generateSoulsTweet() string {
	return "adsfasdfsa"
}

type TwitterCreds struct {
	ConsumerKey    string
	ConsumerSecret string
	AccessToken    string
	AccessSecret   string
	Username       string
}

func getCreds(configFilename *string) (*twitter.Client, error) {
func loadConfig(configFilename *string) (*TwitterCreds, error) {
	file, err := os.Open(*configFilename)
	if err != nil {
		return nil, err


@@ 42,6 59,10 @@ func getCreds(configFilename *string) (*twitter.Client, error) {
	if err != nil {
		fmt.Println("error:", err)
	}
	return &configuration, nil
}

func getTwitterClient(configuration *TwitterCreds) (*twitter.Client, error) {
	config := oauth1.NewConfig(configuration.ConsumerKey, configuration.ConsumerSecret)
	token := oauth1.NewToken(configuration.AccessToken, configuration.AccessSecret)
	httpClient := config.Client(oauth1.NoContext, token)