twitterbots-go

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

commit 08507926089a8c2876dc9051c96de934b554e013
parent 54a11b72536e24f24d9a29474cefc14b5a3d40f4
Author: alex wennerberg <alex@alexwennerberg.com>
Date:   Sat, 26 Sep 2020 22:33:32 -0700

finished config, tested tweet from accounts

Diffstat:
Mmain.go | 27++++++++++++++++++++++++---
1 file changed, 24 insertions(+), 3 deletions(-)

diff --git a/main.go b/main.go @@ -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)