Browse Source

Move variables initialization outside the for loop

pull/6/head
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()
favs <- c()
murl <- c()
acct <- c()
mastodon_instance <- "https://mastodon.social"
mastodon_hashtag <- "ilovefs"
mastodon_url <- paste0(mastodon_instance,
"/api/v1/timelines/tag/",
mastodon_hashtag,
"?limit=40")
for(i in 1:999){
if(i == 1){
mastodon_instance <- "https://mastodon.social"
mastodon_hashtag <- "ilovefs"
mastodon_url <- paste0(mastodon_instance,
"/api/v1/timelines/tag/",
mastodon_hashtag,
"?limit=40")
} else {
mastodon_lheader <- parse_headers(mastodon_reqres$headers)[11]
mastodon_next <- sub(x = mastodon_lheader, pattern = ".*link:\ <", replace = "")
mastodon_url <- sub(x = mastodon_next, pattern = ">;\ rel=\"next\".*", replace = "")
}
mastodon_reqres <- curl_fetch_memory(mastodon_url)

mastodon_rawjson <- rawToChar(mastodon_reqres$content)
toots <- fromJSON(mastodon_rawjson)

@@ -303,6 +298,12 @@ for(i in 1:999){
} else {
break
}

# Update the URL for the next iteration of the for loop so we can download
# the next toots.
mastodon_lheader <- parse_headers(mastodon_reqres$headers)[11]
mastodon_next <- sub(x = mastodon_lheader, pattern = ".*link:\ <", replace = "")
mastodon_url <- sub(x = mastodon_next, pattern = ">;\ rel=\"next\".*", replace = "")
}

### Time of post

Loading…
Cancel
Save