【发布时间】:2021-04-01 10:30:19
【问题描述】:
我正在使用 Discogs API,试图为我的收藏提取社区信息(拥有和想要、最低价格等)。
不幸的是,它的速率限制为每分钟 25 次,我无法找到一种方法将该限制应用到我当前的代码中(见下文)。 我可以使用 sys.sleep(),但我不确定它在代码中的位置。
communityData <- lapply(as.list(collection$release_id), function(obj){
url <- httr::GET(paste0("https://api.discogs.com/releases/", obj))
url <- rjson::fromJSON(rawToChar(url$content))
data.frame(release_id = obj,
label = url$label[[1]]$name %||% NA,
year = url$year %||% NA,
title = url$title %||% NA,
artist_name = url$artist[[1]]$name %||% NA,
styles = url$styles[[1]] %||% NA,
genre = url$genre[[1]] %||% NA,
average_note = url$community$rating$average %||% NA,
votes = url$community$rating$count %||% NA,
want = url$community$want %||% NA,
have = url$community$have %||% NA,
lowest_price = url$lowest_price %||% NA,
country = url$country %||% NA)
}) %>% do.call(rbind, .) %>%
unique()
如有任何帮助,我们将不胜感激!
【问题讨论】: