Created
October 23, 2021 16:51
-
-
Save MattSandy/6dd53964ce92f109300a56dcb68af17c to your computer and use it in GitHub Desktop.
Looks at number of Reddit comments in the last 60 days
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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