Skip to content

Instantly share code, notes, and snippets.

@MattSandy
Created October 23, 2021 16:51
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 MattSandy/6dd53964ce92f109300a56dcb68af17c to your computer and use it in GitHub Desktop.
Save MattSandy/6dd53964ce92f109300a56dcb68af17c to your computer and use it in GitHub Desktop.
Looks at number of Reddit comments in the last 60 days
library(tidyverse)
library(glue)
library(jsonlite)
library(lubridate)
df <- c("user_a","user_b") %>%
lapply(function(user){
after <- ""
df <- list()
for(i in 1:40) {
json <- fromJSON(glue("https://www.reddit.com/user/{user}/comments/.json?after={after}"))
df[[i]] <- json$data$children$data
after <- json$data$after
}
df %>% bind_rows() %>%
select(author,created_utc) %>%
mutate(date_time = lubridate::as_datetime(created_utc)) %>%
filter(!duplicated(date_time)) %>%
return()
}) %>% bind_rows()
df %>%
filter(date_time > max(date_time) - days(60)) %>%
group_by(author) %>%
summarise(n = n()) %>% knitr::kable()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment