Skip to content

Instantly share code, notes, and snippets.

@hadley
Last active September 26, 2022 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadley/5dc9f7a8082cd763f144b096cf7051fe to your computer and use it in GitHub Desktop.
Save hadley/5dc9f7a8082cd763f144b096cf7051fe to your computer and use it in GitHub Desktop.
library(rtweet)
library(tidyverse)
auth_setup_default()
json <- search_tweets("#rstats", n = 5000, include_rts = FALSE, parse = FALSE)[1:5]
tweets <- tibble(json = json) %>%
unnest_wider(json) %>%
select(statuses) %>%
unnest_longer(statuses) %>%
unpack(statuses) %>%
unpack(entities)
bad_tags <- c("5G", "Serverless", "IoT", "IIoT", "AI", "100DaysOfCode", "DEVCommunity", "FemTech")
simple <- tweets %>%
mutate(id = id_str, user_id = user$id_str, screen_name = user$screen_name, full_text, hashtags = map(hashtags, "text"), .keep = "none") %>%
mutate(n_bad = map_int(hashtags, \(tags) sum(tags %in% bad_tags)))
existing <- rtweet:::TWIT_get(NULL, "/1.1/mutes/users/ids", params = list(stringify_ids = TRUE))
bad <- simple %>%
filter(n_bad > 2) %>%
filter(!user_id %in% existing$ids) %>%
count(screen_name, user_id, sort = TRUE)
bad
walk(bad$user_id, function(id) {
message("Muting ", id)
post_mute(id)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment