Foswiki script import from CSV

83 Views Asked by At

I am using Foswiki to pull together many different source of data in to one place

Most of the source I can import easily, but one source is table exported from database to CSV, I want each line of this CSV to be a different topic on foswiki and there are hundreds of lines

I believe I will need to write a script to solve this problem but I struggle to fine the best place to start, I am comfortable a lot coding languages so I am open to try anything

What suggestions do people have?

1

There are 1 best solutions below

0
On

Foswiki's data store is text based. You can use a command line perl script that takes the CSV as input and writes a file TopicName.txt that contains the topic text as you would like to have it. Move the file to the web where it should be stored and it will appear in your WebTopicList.

The script would be this:

#!/usr/bin/perl -w

while( <DATA> ) {
  chomp;
  @line = split ",";
  open TOPIC, ">$line[0]";
  print TOPIC $line[1];
  close TOPIC;
}
__END__
MyFirstTopic,This is the content of my first topic 
MySecondTopic,This is the content of my second topic