Not logged in. · Lost password · Register
Forum: General Help and Support General Stuff RSS
importing with CSV create new pages
Avatar
teeber99 #1
Member since Jan 2019 · 5 posts
Group memberships: Members
Show profile · Link to this post
Subject: importing with CSV create new pages
I would like to create a new Dokuwiki automatically creating 1000 new pages by importing a single CSV or EXCEL file containing 1000 rows. Where the column fields in the CSV file will populate the subheadings on each page. Is there a plugin or command that does that.

oh....also if that works, I would like to export the whole thing back into a CSV file.
Avatar
turnermm (Moderator) #2
Member since Oct 2009 · 4724 posts · Location: Canada
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
I don't think you will find this as a plugin, but you might be able to find someone on wikimatrix who will be able to write a script that can do this for you.

https://www.wikimatrix.org/consultants
Myron Turner
github: https://github.com/turnermm
plugins, templates: http://www.mturner.org/devel
Avatar
cziehr #3
Member since Jan 2011 · 628 posts · Location: 10119 Berlin
Group memberships: Members
Show profile · Link to this post
In reply to post #1
Since this is a special use case, I don't think there is a plugin for this.

But it is not difficult to write a script which populates your wiki-pages from your csv-file.
Avatar
turnermm (Moderator) #4
Member since Oct 2009 · 4724 posts · Location: Canada
Group memberships: Global Moderators, Members, Super Mods
Show profile · Link to this post
But it is not difficult to write a script which populates your wiki-pages from your csv-file
True, but his request implies that e can't do it himself.
Myron Turner
github: https://github.com/turnermm
plugins, templates: http://www.mturner.org/devel
Avatar
cziehr #5
Member since Jan 2011 · 628 posts · Location: 10119 Berlin
Group memberships: Members
Show profile · Link to this post
@teeber99: If you are working on a linux machine, I could provide a bash script for the creation of pages out of a csv-file, I‘ve done this a week ago on myself. You only have to change some details to your needs, but I could help you with this also.

If you‘re working on windows, I‘m afraid I can‘t help you, because I‘m not familiar with windows batch files.
But it would be the same as in the linux bash-script: read a line of your csv using a for-loop, saving the single fields into an array, and then read the array and write each field of the array as a subheading to your new wiki page.

If you have a basic knowledge about programming, this is no big thing. Can you tell us about your skills?
Avatar
teeber99 #6
Member since Jan 2019 · 5 posts
Group memberships: Members
Show profile · Link to this post
Thank you for your quick reply. Although my computer skills are not so good (I am the DB content guy), my coworker YZ is a computer wizz.  He could modify and implement your bash script in Linux. That would be a great help.
Avatar
cziehr #7
Member since Jan 2011 · 628 posts · Location: 10119 Berlin
Group memberships: Members
Show profile · Link to this post
I've created a script for you:

#!/bin/bash

# save field seperator to variable
OLDIFS=$IFS
# set field seperator for the csv-file
IFS=,

# Read line after line from the csv-file. In every line, the fields are seperated by the seperator defined in IFS. If you want to use , in your headings, chose another seperator like # for example. You have to change IFS=, to IFS=# and in the next line while IFS=, read ... to while IFS=# read ...
while IFS=, read -r FILENAME TITLE HEADING1 HEADING2 HEADING3 HEADING4
do
    # create subdirectory if it not exists
    mkdir -p ./import
    WIKIPAGE="./import/$FILENAME.txt"
   
    echo "====== $TITLE ======" > $WIKIPAGE
    echo >> $WIKIPAGE
    echo "===== $HEADING1 =====" >> $WIKIPAGE
    echo >> $WIKIPAGE
    echo "===== $HEADING2 =====" >> $WIKIPAGE
    echo >> $WIKIPAGE
    echo "===== $HEADING3 =====" >> $WIKIPAGE
    echo >> $WIKIPAGE
    echo "===== $HEADING4 =====" >> $WIKIPAGE

    echo "Page $TITLE created!"

done < import.csv

# restore field seperator
IFS=$OLDIFS

You have to put your csv in the same directory as this script. The csv could have this content:

animals,Animals,Cat,Dog,Horse,Snake
fruits,Fruits,Apple,Banana,Orange,Pineapple
capitals,Capitals,London,Paris,Berlin,Washington

After starting the script (don't forget to make it executable, for example with chmod +x import.sh (where import.sh is the filename of the script), you will get this files in the subdirectory import:

File animals.txt
====== Animals ======

===== Cat =====

===== Dog =====

===== Horse =====

===== Snake =====

File capitals.txt
====== Capitals ======

===== London =====

===== Paris =====

===== Berlin =====

===== Washington =====

File fruits.txt
====== Fruits ======

===== Apple =====

===== Banana =====

===== Orange =====

===== Pineapple =====

I've put the script, the csv and the generated pages in a zip-file in the attachement.

I really love DokuWiki for its simplicity in storing contents!

Greetings,
Christoph

EDIT: I forgot to say: file names can't have spaces, uppercase letters or any other special chars in it, otherwise DokuWiki won't recognize them!
The author has attached one file to this post:
csv to wiki.zip 1.5 kBytes
You have no permission to open this file.
This post was edited on 2019-01-12, 20:35 by cziehr.
Avatar
teeber99 #8
Member since Jan 2019 · 5 posts
Group memberships: Members
Show profile · Link to this post
Subject: Thank you!
Thank you so much Christoph. We will modify our file and try to implement this script. We will get back to you about how it worked.
When we get the first version of the Doku wiki up and public we will show you the result...Thanks
Avatar
teeber99 #9
Member since Jan 2019 · 5 posts
Group memberships: Members
Show profile · Link to this post
Hi Christoph....Where do we put the file generated by your script...import.sh. Into what Dokuwiki directory?  Teeber99 and YZ
Avatar
cziehr #10
Member since Jan 2011 · 628 posts · Location: 10119 Berlin
Group memberships: Members
Show profile · Link to this post
In your DokuWiki-directory, you‘ve got a folder called data. In this folder, there is a subfolder called pages. This is the folder where all your wiki-pages are stored. If you put the files in this folder, they will be in the root directory of your DokuWiki. Maybe you want to put them in a namespace, then simply create a subfolder in the folder pages which is called like the subnamespace you want to use. Please note that the rules for pagenames (no whitespaces etc.) also apply on namespaces.

Further information about namespaces can be found at https://www.dokuwiki.org/namespaces

Greetings,
Christoph
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters:
Go to forum
Imprint
This board is powered by the Unclassified NewsBoard software, 20150713-dev, © 2003-2015 by Yves Goergen
Current time: 2019-11-17, 12:28:00 (UTC +01:00)