From 1f4c27959a88ed19bf70a5927ab321aa9053788b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Canouil?= <8896044+mcanouil@users.noreply.github.com> Date: Sat, 28 Jan 2023 17:26:23 +0100 Subject: [PATCH] fix: ensure tweet post a "new" item (#262) --- .github/assets/post-item.R | 26 ++++++++++++++++++-------- .github/workflows/post-item.yml | 2 +- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/.github/assets/post-item.R b/.github/assets/post-item.R index 335582b..efc4617 100644 --- a/.github/assets/post-item.R +++ b/.github/assets/post-item.R @@ -16,8 +16,8 @@ items <- sapply( "## Blog posts", "## Talks and videos", "## Continuous integration / Continuous deployment", - "## Extensions"#, - # "## Templates" + "## Extensions", + "## Templates" ), FUN = function(x, cat) { if (!x[[1]] %in% cat) return(NULL) @@ -35,7 +35,7 @@ items <- sapply( ) items <- c( paste( - paste("From #AwesomeQuarto:", unlist(items[!sapply(items, is.null)], use.names = FALSE)), + paste("🤖 From #AwesomeQuarto:", unlist(items[!sapply(items, is.null)], use.names = FALSE)), "#QuartoPub", sep = "\n" ) @@ -51,10 +51,9 @@ items[which(over_char > 0)] <- mapply( x = sprintf(".{%s}\n#QuartoPub$", over_char[which(over_char > 0)] + 4), y = items[which(over_char > 0)] ) -set.seed(as.numeric(format(Sys.Date(), "%Y%m%d"))) -item <- sample(items, 1) library(rtweet) +# auth_setup_default() auth <- rtweet::rtweet_bot( api_key = Sys.getenv("TWITTER_API_KEY"), api_secret = Sys.getenv("TWITTER_API_KEY_SECRET"), @@ -63,18 +62,29 @@ auth <- rtweet::rtweet_bot( ) rtweet::auth_as(auth) +past_tweet <- sub(".*: '(.*)' \\(.*", "\\1", unique(grep( + "From #AwesomeQuarto", + get_timeline(user = rtweet:::api_screen_name(), n = 200)[["full_text"]], + value = TRUE +))) + +item <- sample( + items[ + !sub(".*: '(.*)' \\(.*", "\\1", items) %in% past_tweet + ] +) + i <- 0 -while(inherits(try(rtweet::post_tweet(status = paste("🤖", item))), "try-error") & i < 3) { +while(inherits(try(rtweet::post_tweet(status = item)), "try-error") & i < 3) { message(sprintf("Try: %s", i)) i <- i + 1 } - # library(rtoot) # rtoot_token <- rtoot:::get_token_from_envvar() # i <- 0 -# while(inherits(try(rtoot::post_toot(status = paste("🤖", item))), "try-error") & i < 3) { +# while(inherits(try(rtoot::post_toot(status = item)), "try-error") & i < 3) { # message(sprintf("Try: %s", i)) # i <- i + 1 # } diff --git a/.github/workflows/post-item.yml b/.github/workflows/post-item.yml index c912e95..f8fcfe0 100644 --- a/.github/workflows/post-item.yml +++ b/.github/workflows/post-item.yml @@ -4,7 +4,7 @@ name: Post Item on: workflow_dispatch: schedule: - - cron: "0 12 * * mon,wed,fri" + - cron: "0 12 * * *" concurrency: group: ${{ github.workflow }}