CSVGrab is a variation of one of my other plugins FeedGrab, and allows you to import data from a CSV file into a weblog.
Usage is similar to FeedGrab, the template:
{exp:csvgrab url="http://www.url.co.uk/products.csv"
weblog="5"
title="1"
skip="6"
delimiter="TAB"
encloser=""
use="2|3"
fields="prod_description|prod_keywords" }
imports a tab delimited CSV file into the weblog with id of 5, skipping the first 6 lines.
It uses column 1 as the title field, and columns 2 and 3 as the custom fields prod_description and prod_keywords.
delimiter is the character that separates the columns, encloser is the character that wraps the column.
eg, “Title”,”Description”,”Keywords” has a comma delimiter and a quote encloser.
The plugin was developed for a particular client’s requirements - let me know if there are any future development requests.
Edit: Please see the CSVGrab page to download current version
Edit:
I’ve created a support forum on my own site:
http://brandnewbox.co.uk/forums
Can I recommend further problems are raised there. I am more likely to see them and each can have there own thread.
I’ve added this here - I hope you’ll keep that updated if you get this added to the plugins site, etc. Great tool, thank you. =)
I just imported a test run of posts into one of my categories. If you look at the plug-in code, you’ll find several variables that aren’t documented yet. One of them is “cats”. I don’t know how it works just yet, but my test was successful in defining it like this:
<pre><code>exp:csvgrab url=”http://www.mydomainname.com/products.csv” weblog=”7” cats=”Social Studies Curriculum” title=”1” skip=”1” delimiter=”,” encloser=”QUOTE” use=”2|3|4” fields=”summary|body|metakeywords }</code></pre>
Metakeywords is a custom field we use to include in our headers.
I don’t know if you can put more than one category in (the variable name suggests you can).
BTW: If you have non-printable characters in your CSV your posts will have ugly ASCII characters in some places. I was able to fix these in Xcel with the “CLEAN()” function.
Hope that helps.
This is all rather untested, so use at your own peril…
The category parameter puts all entries into a specified category.
You can use the category name or id, eg:
category="Arts"
or
category="1"
Alternatively, you can get the category from the CSV file, using the category_field and category_group parameters.
category_field selects which column to use, and new categories are created if they do not exist. It currently does not do anything clever to separate multiple categories.
The category_group parameter is the id of the category group into which the new categories should be added (can be found on the Admin › Weblog Administration › Category Groups page in the Control Panel).
eg,
category_field="4"
category_group="3"
I should reiterate: this has not been tested very stringently - it was added for a client who eventually did not need it - which is why I had not documented it yet.
Let me know how you get on - I will try to fix any bugs and I’m open to feature requests.
Good luck!
Hi Andrew me again.
If I’m reading your php correctly it looks like you’ve hard-coded the author id. Would it be possible to have this as a field to be pulled from the csv either by id or display name (pref display name)?
I’d also like to be able to set the entry date (& time if we can) from the csv. It looks like your using current time at the moment.
Thanks again and I hope you don’t mind me asking.
OK I’m not getting this to work…
I figured I’d try my simple import first.
“Bands Name”,”Bands URL”
So here’s my CSVGrab tag
{exp:csvgrab url="http://acuityimages.com/v2_bands.csv"
weblog="18"
title="1"
skip="6"
delimiter=","
encloser="QUOTE"
use="2"
fields="v2_bandvenues_url" }
Here’s a couple of lines of my csv (and the rest is attached)
"1990's","http://www.myspace.com/1990sband"
"22/20s","http://www.myspace.com/2220s"
"65daysofstatic","http://www.65daysofstatic.com/"
"69 Eyes","http://www.69eyes.com/"
"747s","http://www.747s.co.uk/"
I upload the csv go to my csvgrab template and it starts to load. after maybe 30-40s a blank entry appears after that nothing it just keeps spinning and adding no more entries. real or empty like the first one.
Have I missed something?
Well I’ve continued to try and get this to work but I’m failing miserably.
I’ve changed the CSVGrab tag to
{exp:csvgrab url="http://acuityimages.com/test.csv" weblog="18" title="1" delimiter="TAB" use="2" fields="v2_bandvenues_url" }
and my csv file is now
65daysofstatic http://www.65daysofstatic.com/
69 Eyes http://www.69eyes.com/
747s http://www.747s.co.uk/
I figured I’d go simple and just TAB separate the data and try it with a smaller amount of data…
But I still get nothing. Occasionally CSVGrab will insert a blank entry but 9/10 times the loading icon just spins in firefox and NOTHING happens.
I thought it might be getting hung up on the special characters in some bands names (’ - etc) so i took those out but still no dice.
Can anyone clarify that they’ve got CSVGrab working and tell me if my data is wrong?
Thanks in advance.
DJ
Hi David,
Sorry for not replying sooner - for some reason I’ve only just seen your last couple of posts.
I’ve just tested the code in your last post:
{exp:csvgrab url="http://acuityimages.com/test.csv" weblog="18" title="1" delimiter="TAB" use="2" fields="v2_bandvenues_url" }
and it works fine for me (when I change were the weblog and fields to parameters to appropriate ones for my setup).
Are you still having problems?
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.