Browse Source

Add mastodon toots dataframe

pull/2/head
vincent 1 year ago
parent
commit
f5e7eed98b
1 changed files with 15 additions and 0 deletions
  1. 15
    0
      collecto.R

+ 15
- 0
collecto.R View File

@@ -160,6 +160,21 @@ twitter <- within(data = twitter, expr = {
})
# }}}

## Mastodon Collector with curl {{{ ----

library(curl)
library(rjson)
toot_raw_json <- rawToChar(curl_fetch_memory("https://mastodon.social/api/v1/timelines/tag/ilovefs?limit=40")$content)
toots = fromJSON(toot_raw_json)
toots_mat = matrix(ncol = 4, nrow = length(toots))
for(i in 1:length(toots)){
toots_mat[i,] <- c(toots[[i]]$created_at, toots[[i]]$url, toots[[i]]$content, toots[[i]]$language)
}
toots_df = data.frame(toots_mat)
names(toots_df) = c ('created_at', 'url', 'content', 'language')
toots_df$content <- gsub(pattern = "<.*?>", x = toots_df$content, replacement = "")
toots_df$content <- gsub(pattern = " ", x = toots_df$content, replacement = "")

## Mastodon Collector {{{ ----

### Authenticate to the Fediverse (here: Mastodon)

Loading…
Cancel
Save