CSV import format

Any trouble you encounter with the Pedias, here's the place to ask for help.
Post Reply
ken
Junior Member
Junior Member
Posts: 3
Joined: Tue Oct 16, 2007 9:06 am

CSV import format

Post by ken »

I'm evaluating Bookpedia and attempting to import our library records. I have a CSV file (generated from our old software), but I can't seem to find a specification for what format Bookpedia expects.

Specifically:
  1. How should authors be specified? "First Last" or "Last, First"? How about multiple authors for a book?
  2. How should newlines (e.g. inside book descriptions) or double-quotes be specified inside fields? For newlines I've tried \n, an actual newline character, and &newline;. None seem to work.
Thanks,

-Ken
User avatar
Nora
Site Admin
Posts: 2155
Joined: Sun Jul 04, 2004 5:03 am
Contact:

Post by Nora »

The author listing in Bookpedia is up to you really but almost all the search sites (especially Amazon) will return the author as 'First Last'. Keep in mind that with this setting you can still sort the authors by last name in Bookpedia. Just hold down the option key while sorting the author column.
Multiple authors can be separated pretty much by whatever you want (comma, slash, etc.) But if you want to use the option sorting trick to sort the column by last name I'd suggest using a comma.

Regarding newlines - you could replace all newlines with \r (carriage return) but leave the entry separator \n (newline). However since that's kind of complicated and you suggested it, we have added "\n" (not the newline character but the actual backslash and N) as an alternative. Download Bookpedia again and "\n" will be converted into newline characters.

Example:
title comments summary
First book comments\nsecond line\nthird line summary\nline\nline
Second book comments without lines summary with\nlines in it

You shouldn't have any trouble with double-quotes because Bookpedia actually looks for "," to separate entries (or a tab).

Example:
"title","comments","summary"
"title","comments and " two " quotes","summary with a " in it plus "mary""
"title","comments said "hello"","summary with\nlines in it\nhello there"
ken
Junior Member
Junior Member
Posts: 3
Joined: Tue Oct 16, 2007 9:06 am

Post by ken »

Excellent, thanks. Amazing turnaround time on the patched release. :D

The conversion code I used was as follows:

Code: Select all

perl -nle 'chomp; @f=split /", "/; for(@f) {s/&newline;/\\n/g; s/&doublequote;/"/g} if($.==1) {splice @f,43,5}else{@authors=grep/\S/,$f[1],splice@f,43,5; for(@authors) {s/(.+),\s*(.+)/$2 $1/} $f[1]=join", ",@authors} print join q{","}, @f' Library.csv > Library-fixed.csv
-Ken
User avatar
Conor
Top Dog
Posts: 5344
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Post by Conor »

Thank you for sharing your conversion code, I must say that some serious pearl skill.
ken
Junior Member
Junior Member
Posts: 3
Joined: Tue Oct 16, 2007 9:06 am

Post by ken »

You should see me when I really get going. ;-)

I forgot to mention, one of the crucial steps in there is converting ", " to "," , because the original export had spaces after its commas, despite the fact that most CSV readers don't recognize that.

-Ken
Post Reply