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

with page name pattern using csv columns

parent 8ddd016a
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.3
Version: 0.1.4
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
......
......@@ -255,8 +255,7 @@ Batchator <- R6Class("Batchator",
public = list(
author = NULL,
wiki = NULL,
page_prefix ="",
page_names=NULL,
page_name_pattern=NULL,
template = NULL,
field_list = NULL,
content = NULL,
......@@ -264,10 +263,9 @@ Batchator <- R6Class("Batchator",
######
# initialize
######
initialize = function (wiki,author,pass,prefix){
initialize = function (wiki,author,pass){
tryCatch({
self$wiki <- Mediawikir$new(wiki, author, pass)
self$page_prefix <- prefix
},
error = function(e){
print(e$message)
......@@ -287,6 +285,13 @@ Batchator <- R6Class("Batchator",
})
},
######
# setPageNamePattern
######
setPageNamePattern = function(naming_pattern){
self$page_name_pattern = naming_pattern
},
######
# loadContent
######
......@@ -294,7 +299,6 @@ Batchator <- R6Class("Batchator",
tryCatch({
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){
......@@ -309,17 +313,19 @@ Batchator <- R6Class("Batchator",
tryCatch({
if (is.null(self$content) |
is.null(self$field_list) |
is.null(self$page_names) |
is.null(self$page_name_pattern) |
is.null(self$template)) {
warning("Either no content or no template, use loadContent and/or loadTemplate.")
warning("Either no content or no templates, use loadContent, setPageNamePattern 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)))
self$wiki$setPage(paste(self$page_prefix,self$page_names[i],sep = ""))
#self$wiki$postContent()
self$wiki$setPage(str_replace_all(self$page_name_pattern,
setNames(as.vector(t(self$content[i,])),
self$field_list)))
self$wiki$postContent()
}
}
},
......
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