R/page_id.R

#' Getting the ID of a list of pages
#'
#' @param pages A character vector of pages title. 
#' @param domain The domain where the wiki is located
#' 
#' @importFrom plyr llply
#' @import magrittr
#'
#' @return A data-frame with id, namespace and title column
#' @export
#'
page_id <- function(pages, domain = "fr") {
  
  id <- divide_list(pages) %>%
    llply(function(x) {
      
      query <- list(
        action = "query",
        format = "json",
        indexpageids = "1",
        titles = x,
        redirect = ""
      )
      
      dat <- exec_query(query)
      
      if(!is.null(dat)) {
        
        dat$query$pageids %>% as.numeric()
        
      } else {
        
        warning("Network problem - results may be incomplete")
        
      }
      
    }, .progress = "text") %>% unlist
  
  data.frame(pages, id)
  
}
leojoubert/WikiSocio documentation built on May 21, 2019, 5:08 a.m.