-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtweets_32beatwriters.R
36 lines (31 loc) · 1.14 KB
/
tweets_32beatwriters.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
library(rtweet)
library(arrow)
library(dplyr)
library(purrr)
twitter_token <- rtweet::rtweet_bot(
api_key = Sys.getenv("TWITTERAPIKEY"),
api_secret = Sys.getenv("TWITTERAPISECRET"),
access_token = Sys.getenv("TWITTERACCESSTOKEN"),
access_secret = Sys.getenv("TWITTERACCESSTOKENSECRET")
)
min_id <- arrow::open_dataset("data/32beatwriters", format = "csv") %>%
select(status_id) %>%
collect() %>%
filter(status_id == max(status_id)) %>%
pull(status_id)
tweets_32 <- rtweet::get_timeline(user = "32beatwriters",
n = 3200,
token = twitter_token) %>%
filter(status_id >= min_id) %>%
mutate(
year = format(created_at, "%Y"),
month = format(created_at, "%m"),
across(where(is.list),~paste(collapse = "; ")),
across(contains("created_at"), as.character)
)
basename_template <- paste0("tweets_",Sys.Date(),"_{i}",".csv")
arrow::write_dataset(tweets_32,
path = "data/32beatwriters",
format = "csv",
basename_template = basename_template,
partitioning = c("year","month"))