Browse Source

Add mastodon toots dataframe

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 = {
160 160
 		  })
161 161
 # }}}
162 162
 
163
+## Mastodon Collector with curl {{{ ----
164
+
165
+library(curl)
166
+library(rjson)
167
+toot_raw_json <- rawToChar(curl_fetch_memory("https://mastodon.social/api/v1/timelines/tag/ilovefs?limit=40")$content)
168
+toots = fromJSON(toot_raw_json)
169
+toots_mat = matrix(ncol = 4, nrow = length(toots))
170
+for(i in 1:length(toots)){
171
+    toots_mat[i,] <- c(toots[[i]]$created_at, toots[[i]]$url, toots[[i]]$content, toots[[i]]$language)
172
+}
173
+toots_df = data.frame(toots_mat)
174
+names(toots_df) = c ('created_at', 'url', 'content', 'language')
175
+toots_df$content <- gsub(pattern = "<.*?>", x = toots_df$content, replacement = "")
176
+toots_df$content <- gsub(pattern = "  ", x = toots_df$content, replacement = "")
177
+
163 178
 ## Mastodon Collector {{{ ----
164 179
 
165 180
 ### Authenticate to the Fediverse (here: Mastodon)

Loading…
Cancel
Save