Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-07-15 21:30:45

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

jmd_csv: Batch-import articles from a CSV

Download 0.2 (Requires PHP5 and 4.0.6)

Last edited by jm (2008-12-01 04:01:11)

Offline

#2 2008-07-15 21:40:45

mrdale
Member
From: Walla Walla
Registered: 2004-11-19
Posts: 2,215
Website

Re: jmd_csv: Batch-import articles from a CSV

Supremely useful. Giving it a spin.

Offline

#3 2008-07-16 00:00:12

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

Re: jmd_csv: Batch-import articles from a CSV

Coolio – I will check this out later – many thanks

Offline

#4 2008-07-16 01:17:01

renobird
Member
From: Gainesville, Florida
Registered: 2005-03-02
Posts: 786
Website

Re: jmd_csv: Batch-import articles from a CSV

You’re on fire my man!

Too bad for me that I needed this 8 months ago.

Going to give it a go anyhow – just to see if I can break it.

)

Offline

#5 2008-07-16 13:44:24

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,596
Website

Re: jmd_csv: Batch-import articles from a CSV

It’ll be a time-saver extraordinaire for repetitive article types. Will try it out asap. Thank you!


TXP Builders – finely-crafted code, design and txp

Offline

#6 2008-08-05 08:04:04

tye
Member
From: Pottsville, NSW
Registered: 2005-07-06
Posts: 859
Website

Re: jmd_csv: Batch-import articles from a CSV

This works a treat… thanks.

It would be even better if it automatically created the sections, categories and custom_fields – but hey, that’s just me getting lazy :)

I love it though – great time saver

Thanks

Offline

#7 2008-09-22 22:20:29

pbrienesse
Member
Registered: 2008-03-14
Posts: 10

Re: jmd_csv: Batch-import articles from a CSV

Didn’t work with an excel csv but pasting into google docs and exporting as a csv worked wonderfully. We had an old site based on Action Apps that broke when the server upgraded to php5. The only access we could get was the sql database. This plugin has saved me a ton of work re-entering all the entries. It does produce a number of errors on import, but all the articles import just fine anyway. (update: errors were produced by any field that contained an ‘ such as Wet’sewet’en. Those articles were not imported either)

Thanks

Last edited by pbrienesse (2008-09-22 23:16:17)

Offline

#8 2008-11-21 01:36:08

damienbuckley
Member
From: Brisbane, QLD, AU
Registered: 2006-02-24
Posts: 138
Website

Re: jmd_csv: Batch-import articles from a CSV

Any reason why this only works with Google Docs? not having much luck with it I’m afraid.

Offline

#9 2008-11-21 08:13:26

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 4,596
Website

Re: jmd_csv: Batch-import articles from a CSV

Just a guess as I don’t know google docs but sometimes I have problems (unrelated to this plugin) with csv files sent to me by other people and usually it is down to different separators (comma, semi-colon etc.) having been used.


TXP Builders – finely-crafted code, design and txp

Offline

#10 2008-11-21 21:39:33

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: jmd_csv: Batch-import articles from a CSV

Excel (at least Mac ’04) doesn’t work out of the box because of it’s CR line endings, but if you open the CSV in a text editor and re-save it with LF line endings, it should work. I’ll see about modifying the file on the server before importing.

0.2 is up too. It escapes all output for insertion, in the event you have a lazy CSV editor.

Last edited by jm (2008-11-21 21:39:45)

Offline

#11 2008-11-27 15:50:31

azw
Member
Registered: 2007-01-29
Posts: 279

Re: jmd_csv: Batch-import articles from a CSV

Thanks for this plug-in, JM. I think it’ll save a lot of hours.

UPDATE: Please see my second message. You can skip this first one (msg #11). I’ve taken a different approach.

Would it be possible to change to a different delimiter? May be a character like, | , ~ , or ^ ? I have text with lots of commas in it. Can I edit the plug-in, perhaps in this line?

       while (($csv = fgetcsv($handle, 0, ',')) !== FALSE)

I suppose that raises another question: Does anyone know how to generate a csv with a different delimiter?

There’s also an option in Excel to generate a tab delimited .txt file. That might work for me.

How would I represent a tab in this line?

       while (($csv = fgetcsv($handle, 0, 'TAB')) !== FALSE)

Also, I’m having the same problem with Excel csv. Excel offers 3 different kinds of csv formats in the save as function. Maybe one of the others would work?

—————

Okay, I’ve decided to try the tab-delimited.
I’ve replaced the “,” with “\t” by editing the plug-in.
I’ve also saved the excel spreadsheet as a tab-delimited text file and then saved it again as Unix format in Notepad++.

When I run it, I get messages like this:

Warning: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘long=’0.8641’,campaign=‘Omaha-Beach’,doc_type=‘Monthly-After-Action-Reports’,pd’ at line 1 insert into textpattern set Title=‘After Action Report, 29th Infantry Division, June 1944’,Body_html=‘The 29th Division lands on Omaha Beach on D-Day and pushes inland toward St. Lo’,Body=‘The 29th Division lands on Omaha Beach on D-Day and pushes inland toward St. Lo’,Excerpt_html=’‘,Excerpt=’‘,Section=‘documents’,Category1=‘Monthly-After-Action-Reports’,Category2=‘Omaha-Beach’,year=‘1944’,month=‘06’,day=’‘,lat=‘49.3651’,long=’-0.8641’,campaign=‘Omaha-Beach’,doc_type=‘Monthly-After-Action-Reports’,pdf_url=‘AftActRpt
29ID-44-06’,AuthorID=‘art’, LastModID=‘art’, AnnotateInvite=‘Comment’, url_title=‘after-action-report-29th-infantry-division-june-1944’, uid=‘6f2f43a835e0497cfca70b1ca700d0f4’, feed_time=now(), Posted=now(), LastMod=now(), Status=1, textile_body=0, textile_excerpt in /home/a29div/public_html/textpattern/lib/txplib_db.php on line 81

What I am doing wrong?

Last edited by azw (2008-11-29 06:38:47)

Offline

#12 2008-11-29 07:30:43

azw
Member
Registered: 2007-01-29
Posts: 279

Re: jmd_csv: Batch-import articles from a CSV

UPDATE: I’ve tested and see now that a CSV can contain data with commas. I learned something!

I’ll describe what I did, just in case this helps someone else.

It’s worth reading the brief instructions for jmc_csv in the plugins tab.

Steps to use jmd_csv
  1. Create a spreadsheet in Excel and then save it as a cvs
  2. [NOTE: It appears that this step is no longer necessary with version 0.2] Open this csv file in Notepad++. (You can also copy and paste the cells into Google Docs, and export it as CSV, sheet only.)
  3. Upload it to your files folder in TXP, assign it the category of jmd_csv.
  4. Run the jmd_csv routine in the Extensions tab.
  5. Finally, it’s important to verify that the fields all transferred correctly. You may have to tweak your spreadsheet.
Several tips to avoid errors
  1. Don’t include any empty rows in your spreadsheet (otherwise you may have to delete empty articles).
  2. Don’t include any extra spaces at the end of a field of data, especially if TXP will be trying to match the entry with existing categories, custom field sets (if you’re using the glz_custom_fields plugin), etc.
  3. Don’t use the name you have used to label a custom field (e.g. “year”). You can only use custom_1, custom_2, etc.
  4. For Category1 and Category2 you have to use the name (e.g. the hyphenated “two-words”, not the title (e.g. “two words”). (If a name contains multiple words, there will be hyphens instead of spaces and any other punctuation will be removed. There may be other changes, too, but I haven’t tested this.)

Last edited by azw (2008-11-29 17:17:21)

Offline

Board footer

Powered by FluxBB