Browse Source

Merge branch 'curl_mastodon' of vincent/ilfs-data into master

janwey 1 year ago
parent
commit
96b8d4647c
1 changed files with 15 additions and 0 deletions
  1. 15
    0
      collecto.R

+ 15
- 0
collecto.R View File

@@ -154,6 +154,21 @@ twitter <- within(data = twitter, expr = {
154 154
 		  })
155 155
 # }}}
156 156
 
157
+## Mastodon Collector with curl {{{ ----
158
+
159
+library(curl)
160
+library(rjson)
161
+toot_raw_json <- rawToChar(curl_fetch_memory("https://mastodon.social/api/v1/timelines/tag/ilovefs?limit=40")$content)
162
+toots = fromJSON(toot_raw_json)
163
+toots_mat = matrix(ncol = 4, nrow = length(toots))
164
+for(i in 1:length(toots)){
165
+    toots_mat[i,] <- c(toots[[i]]$created_at, toots[[i]]$url, toots[[i]]$content, toots[[i]]$language)
166
+}
167
+toots_df = data.frame(toots_mat)
168
+names(toots_df) = c ('created_at', 'url', 'content', 'language')
169
+toots_df$content <- gsub(pattern = "<.*?>", x = toots_df$content, replacement = "")
170
+toots_df$content <- gsub(pattern = "  ", x = toots_df$content, replacement = "")
171
+
157 172
 ## Mastodon Collector {{{ ----
158 173
 
159 174
 ### Authenticate to the Fediverse (here: Mastodon)

Loading…
Cancel
Save