Skip to content
Snippets Groups Projects
Commit cf8d9596 authored by Mathieu Loiseau's avatar Mathieu Loiseau
Browse files

now needs to upload content

parent 9f20f201
No related branches found
No related tags found
No related merge requests found
Package: mediawikir
Type: Package
Title: Connects to a mediawiki instance and writes in it what you want
Version: 0.1.2
Version: 0.1.3
Author: Mathieu Loiseau
Maintainer: Mathieu Loiseau <loiseaum@univ-grenoble-alpes.fr>
Description: It can be used to post the output of an R script directly into a mediawiki instance
......
......@@ -6,3 +6,5 @@ importFrom(R6,R6Class)
importFrom(httr,POST)
importFrom(httr,content)
importFrom(httr,stop_for_status)
importFrom(httr,upload_file)
importFrom(stringr,str_replace_all)
......@@ -41,6 +41,10 @@ library(httr)
#' \item{\code{pageName}}{The name of the wiki page which contains the changes}
#' }}
#' \item{\code{connect(pass)}}{Should not be called directly (see initialize for detail)}
#' \item{\code{resetContent(baseContent="")}}{To reset the content of the page for the next post
#' \describe{
#' \item{\code{baseContent}}{The wikitext base for the next post}
#' }}
#' \item{\code{addContent(theContent, type="p")}}{To add content that will later on be posted to mediawiki. This is where structuring elements are provided
#' \describe{
#' \item{\code{theContent}}{Either text (using mediawiki syntax) or path to a file}
......@@ -128,6 +132,13 @@ Mediawikir <- R6Class("Mediawikir",
self$page_name <- pageName
},
######
# resetContent
######
resetContent = function(aContent=""){
self$content <- aContent
},
######
# addContent
######
......@@ -233,7 +244,6 @@ Mediawikir <- R6Class("Mediawikir",
)
library(stringr)
#'Batchator: Batch input to mediawiki based on a csv and a template
#'
#'@docType class
......@@ -246,7 +256,9 @@ Batchator <- R6Class("Batchator",
author = NULL,
wiki = NULL,
page_prefix ="",
page_names=NULL,
template = NULL,
field_list = NULL,
content = NULL,
######
......@@ -280,11 +292,43 @@ Batchator <- R6Class("Batchator",
######
loadContent = function(file_path){
tryCatch({
self$content <- read.csv(file=file_path, header = FALSE)
csvM <- read.csv(file=file_path, header = FALSE)
self$field_list <- as.vector(t(csvM[1,]))
self$page_names <- csvM[-1,1]
self$content <- csvM[-1,]
},
error = function(e){
print(paste(e$message, "No content loaded"))
})
},
######
# applyTemplate
######
applyTemplate = function(){
tryCatch({
if (is.null(self$content) |
is.null(self$field_list) |
is.null(self$page_names) |
is.null(self$template)) {
warning("Either no content or no template, use loadContent and/or loadTemplate.")
}
else{
for(i in 1:nrow(self$content)){
self$wiki$resetContent(str_replace_all(self$template,
setNames(as.vector(t(self$content[i,])),
self$field_list)))
print(paste("Content of ",self$page_prefix,self$page_names[i],sep = ""))
print(str_replace_all(self$template,
setNames(as.vector(t(self$content[i,])),
self$field_list)))
}
}
},
error = function(e){
print(e$message)
})
}
)
)
......@@ -42,6 +42,10 @@ A Mediawikir controller serves to connect to a mediawiki API as a registered use
\item{\code{pageName}}{The name of the wiki page which contains the changes}
}}
\item{\code{connect(pass)}}{Should not be called directly (see initialize for detail)}
\item{\code{resetContent(baseContent="")}}{To reset the content of the page for the next post
\describe{
\item{\code{baseContent}}{The wikitext base for the next post}
}}
\item{\code{addContent(theContent, type="p")}}{To add content that will later on be posted to mediawiki. This is where structuring elements are provided
\describe{
\item{\code{theContent}}{Either text (using mediawiki syntax) or path to a file}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment