Difference between revisions of "Import CSV data into a wiki"
m |
m |
||
Line 5: | Line 5: | ||
./csv2wiki.pl /home/myJob.conf | ./csv2wiki.pl /home/myJob.conf | ||
</source> | </source> | ||
+ | |||
Here is an example configuration file: | Here is an example configuration file: | ||
Line 16: | Line 17: | ||
</source> | </source> | ||
− | + | ||
− | Each line of the input file will be imported into an article in the wiki, and the first line of the input file specifies the field names | + | Each line of the input file will be imported into an article in the wiki, and the first line of the input file specifies the field names, for example: |
<source> | <source> | ||
Title, Firstname, Surname | Title, Firstname, Surname | ||
Line 25: | Line 26: | ||
− | In | + | In this example the first row of data will be imported into an article called "Mr Bob McFoo" with the following content: |
<source> | <source> | ||
{{Customer | {{Customer | ||
Line 36: | Line 37: | ||
If the page already existed, then the new template would be inserted at the top of the page (or the bottom if "append" is set). Or if the template already exists in the page, then it's values will be updated. | If the page already existed, then the new template would be inserted at the top of the page (or the bottom if "append" is set). Or if the template already exists in the page, then it's values will be updated. | ||
+ | |||
+ | '''Note''' that pages that already have templates on them must only use a single value on each line in their syntax. | ||
== Configuration options == | == Configuration options == |
Revision as of 21:17, 6 May 2020
csv2wiki is a way to import data from a CSV file into a MediaWiki. The program is run from the shell and requires one parameter which is the filename of a configuration file describing the parameters for the job. It depends on a second script called wiki.pl existing in the same location.
./csv2wiki.pl /home/myJob.conf
Here is an example configuration file:
wiki = "http://foo.bar/wiki/index.php"
user = "Foo"
pass = "Bar"
csv = "/home/foo/projects/bar.csv"
title = "$1 $2 $3"
template = Customer
Each line of the input file will be imported into an article in the wiki, and the first line of the input file specifies the field names, for example:
Title, Firstname, Surname
Mr, Bob, McFoo
Miss, Mary, Barson
In this example the first row of data will be imported into an article called "Mr Bob McFoo" with the following content:
{{Customer
| Title = Mr
| Firstname = Bob
| Surname = McFoo
}}
If the page already existed, then the new template would be inserted at the top of the page (or the bottom if "append" is set). Or if the template already exists in the page, then it's values will be updated.
Note that pages that already have templates on them must only use a single value on each line in their syntax.
Configuration options
Here is a description of the possible parameters in the job file and their meaning:
Name | Meaning | Default value |
---|---|---|
csv | The source file to import relative to the location of the script | - |
wiki | the full long-form URL of the wiki including index.php | - |
user | Username of a user on the wiki with permission to create the necessary articles | - |
pass | The users password | - |
separator | Also just "sep" is allowed, specifies the separator character used in the CSV file | comma |
title | The format of the title using $n to specify the column numbers, default is $1 which means to use just the first columns as the title | $1 |
template | The template that the parameters should be wrapped by in the created wiki articles | Record |
append | Set this to 1 to place the template at the end of the text if the template doesn't already exist in the article | 0 |
include | A comma-separated list of the columns that should be included from the CSV, by default all columns are used | not set |