Skip to content

Commit

Permalink
fix: ensure tweet post a "new" item (#262)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcanouil authored Jan 28, 2023
1 parent fb677ba commit 1f4c279
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
26 changes: 18 additions & 8 deletions .github/assets/post-item.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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"
)
Expand All @@ -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"),
Expand All @@ -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
# }
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/post-item.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name: Post Item
on:
workflow_dispatch:
schedule:
- cron: "0 12 * * mon,wed,fri"
- cron: "0 12 * * *"

concurrency:
group: ${{ github.workflow }}
Expand Down

0 comments on commit 1f4c279

Please sign in to comment.