Skip to content

Commit

Permalink
Fix toot error handling, remove twitter code
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkerlogue committed Apr 24, 2024
1 parent f7842a4 commit 6224097
Showing 1 changed file with 5 additions and 30 deletions.
35 changes: 5 additions & 30 deletions narrowbot.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# narrowbotR
# An R-based Twitter bot that tweets waterway features in England & Wales from
# An R-based Mastodon bot that tweets waterway features in England & Wales from
# the Canal & River Trust network.

# set-up environment ------------------------------------------------------
Expand All @@ -8,14 +8,6 @@
source("R/flickr_functions.R") # flickr api functions
source("R/mastodon_token.R") # custom mastodon token function

# # create twitter token
# twitter_token <- rtweet::rtweet_bot(
# api_key = Sys.getenv("TWITTER_CONSUMER_API_KEY"),
# api_secret = Sys.getenv("TWITTER_CONSUMER_API_SECRET"),
# access_token = Sys.getenv("TWITTER_ACCESS_TOKEN"),
# access_secret = Sys.getenv("TWITTER_ACCESS_TOKEN_SECRET")
# )

# create mastodon token
toot_token <- mastodon_token(
access_token = Sys.getenv("MASTODON_TOKEN"),
Expand Down Expand Up @@ -143,25 +135,13 @@ status_msg <- paste0(msg_text, collapse = "")

# submit post -------------------------------------------------------------

# safely_tweet <- purrr::possibly(rtweet::post_tweet, otherwise = "tweet_error")
safely_toot <- purrr::possibly(rtoot::post_toot, otherwise = "toot_error")

# if testing do not post output
if (Sys.getenv("NARROWBOT_TEST") == "true") {
message("Test mode, will not post to Twitter/Mastodon")
} else {

# # post to twitter
# tweet_out <- safely_tweet(
# status = status_msg,
# media = tmp_file,
# media_alt_text = alt_msg,
# lat = place$lat,
# long = place$long,
# display_coordinates = TRUE,
# token = twitter_token
# )

# post to mastodon
toot_out <- safely_toot(
status = status_msg,
Expand All @@ -170,17 +150,12 @@ if (Sys.getenv("NARROWBOT_TEST") == "true") {
token = toot_token
)

if (!is.null(toot_out$error)) {
stop("Toot unsucessful")
if (is.character(toot_out)) {
if (toot_out == "toot_error") {
stop("Toot unsuccessful")
}
}

# # stop if post to both APIs fail
# if (is.null(tweet_out$error) & is.null(tweet_out$error)) {
# message("Successfully tweeted and tooted")
# } else if (!is.null(tweet_out$error) & is.null(toot_out$error)) {
# stop("Both tweet and toot unsuccessful")
# }

}

# delay to avoid message and cat mixing
Expand Down

0 comments on commit 6224097

Please sign in to comment.