diff --git a/internal/nzcovidbot/csv.go b/internal/nzcovidbot/csv.go index 1525e83..7d87f53 100644 --- a/internal/nzcovidbot/csv.go +++ b/internal/nzcovidbot/csv.go @@ -63,7 +63,7 @@ func formatCsvTwitterRow(data string) string { c := make([]string, 0) c = append(c, fields...) endtime := strings.Split(c[5], ", ") - return fmt.Sprintf("**%s** - %s _%s_ - _%s_", c[1], c[2], c[4], endtime[1]) + return fmt.Sprintf("New Location: *%s\n%s\n_%s_ - _%s_\n#NZCovidBot", c[1], c[2], c[4], endtime[1]) } func getPostableDiscordData() string { @@ -82,20 +82,3 @@ func getPostableDiscordData() string { return strings.Join(rows, "\n") } - -func getPostableTwitterData() string { - if len(updatedLocations.Locations) == 0 { - return "" - } - - rows := make([]string, 0) - for _, location := range updatedLocations.Locations { - if location.ChangeType == "REMOVED" { - rows = append(rows, fmt.Sprintf("REMOVED: %s", location.TwitterData)) - } else { - rows = append(rows, location.TwitterData) - } - } - - return strings.Join(rows, "\n\n") -} diff --git a/internal/nzcovidbot/nzcovidbot.go b/internal/nzcovidbot/nzcovidbot.go index f72212f..4a7266d 100644 --- a/internal/nzcovidbot/nzcovidbot.go +++ b/internal/nzcovidbot/nzcovidbot.go @@ -34,27 +34,20 @@ func Lesgoooo() { } func postTheUpdates() { + // Twitter + go postToTwitter() + // Discord postableDiscordData := getPostableDiscordData() - if postableDiscordData == "" { return } + // Not using go routines so we don't get rate limited for _, discordWebhook := range DiscordWebhooks { postToDiscord(discordWebhook, postableDiscordData) } - // Twitter - // postableTwitterData := getPostableTwitterData() - // if postableTwitterData == "" { - // return - // } - - // for _, discordWebhook := range DiscordWebhooks { - // postToTwitter(discordWebhook, postableTwitterData) - // } - // Clear out posted data! updatedLocations = UpdatedLocations{} } diff --git a/internal/nzcovidbot/twitter.go b/internal/nzcovidbot/twitter.go index 0eebd58..1fce515 100644 --- a/internal/nzcovidbot/twitter.go +++ b/internal/nzcovidbot/twitter.go @@ -16,33 +16,23 @@ type TwitterCredentials struct { var TwitterCreds TwitterCredentials -// getClient is a helper function that will return a twitter client -// that we can subsequently use to send tweets, or to stream new tweets -// this will take in a pointer to a Credential struct which will contain -// everything needed to authenticate and return a pointer to a twitter Client -// or an error -func getClient(creds *TwitterCredentials) (*twitter.Client, error) { - // Pass in your consumer key (API Key) and your Consumer Secret (API Secret) - config := oauth1.NewConfig(creds.ConsumerKey, creds.ConsumerSecret) - // Pass in your Access Token and your Access Token Secret - token := oauth1.NewToken(creds.AccessToken, creds.AccessTokenSecret) +func postToTwitter() { + if TwitterCreds.AccessTokenSecret == "" { + return + } + config := oauth1.NewConfig(TwitterCreds.ConsumerKey, TwitterCreds.ConsumerSecret) + token := oauth1.NewToken(TwitterCreds.AccessToken, TwitterCreds.AccessTokenSecret) httpClient := config.Client(oauth1.NoContext, token) + + // Twitter client client := twitter.NewClient(httpClient) - // Verify Credentials - verifyParams := &twitter.AccountVerifyParams{ - SkipStatus: twitter.Bool(true), - IncludeEmail: twitter.Bool(true), + // Send a Tweet + for _, row := range updatedLocations.Locations { + _, _, err := client.Statuses.Update(row.TwitterData, nil) + if err != nil { + log.Print(err) + } } - - // we can retrieve the user and verify if the credentials - // we have used successfully allow us to log in! - user, _, err := client.Accounts.VerifyCredentials(verifyParams) - if err != nil { - return nil, err - } - - log.Printf("User's ACCOUNT:\n%+v\n", user) - return client, nil }