Browse Source

Move variables initialization outside the for loop

vincent 1 year ago
parent
commit
a0019a3ca7
1 changed files with 13 additions and 12 deletions
  1. 13
    12
      collecto.R

+ 13
- 12
collecto.R View File

@@ -272,20 +272,15 @@ reto <- c()
272 272
 favs <- c()
273 273
 murl <- c()
274 274
 acct <- c()
275
+mastodon_instance <- "https://mastodon.social"
276
+mastodon_hashtag <- "ilovefs"
277
+mastodon_url <- paste0(mastodon_instance,
278
+                       "/api/v1/timelines/tag/",
279
+                       mastodon_hashtag,
280
+                       "?limit=40")
275 281
 for(i in 1:999){
276
-  if(i == 1){
277
-    mastodon_instance <- "https://mastodon.social"
278
-    mastodon_hashtag <- "ilovefs"
279
-    mastodon_url <- paste0(mastodon_instance,
280
-			      "/api/v1/timelines/tag/",
281
-			      mastodon_hashtag,
282
-			      "?limit=40")
283
-  } else {
284
-  mastodon_lheader <- parse_headers(mastodon_reqres$headers)[11]
285
-  mastodon_next <- sub(x = mastodon_lheader, pattern = ".*link:\ <", replace = "")
286
-  mastodon_url <- sub(x = mastodon_next, pattern = ">;\ rel=\"next\".*", replace = "")
287
-  }
288 282
   mastodon_reqres <- curl_fetch_memory(mastodon_url)
283
+
289 284
   mastodon_rawjson <- rawToChar(mastodon_reqres$content)
290 285
   toots <- fromJSON(mastodon_rawjson)
291 286
 
@@ -303,6 +298,12 @@ for(i in 1:999){
303 298
   } else {
304 299
     break
305 300
   }
301
+
302
+  # Update the URL for the next iteration of the for loop so we can download
303
+  # the next toots.
304
+  mastodon_lheader <- parse_headers(mastodon_reqres$headers)[11]
305
+  mastodon_next <- sub(x = mastodon_lheader, pattern = ".*link:\ <", replace = "")
306
+  mastodon_url <- sub(x = mastodon_next, pattern = ">;\ rel=\"next\".*", replace = "")
306 307
 }
307 308
 
308 309
 ### Time of post

Loading…
Cancel
Save