We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: CSVGrab

Development and Programming

Andrew Weaver's avatar
Andrew Weaver
206 posts
18 years ago
Andrew Weaver's avatar Andrew Weaver

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.

       
Andrew Weaver's avatar
Andrew Weaver
206 posts
18 years ago
Andrew Weaver's avatar Andrew Weaver

Further note:

EE ‘cleans up’ plugin parameters, so for delimiter and encloser use the following codes rather than the actual character: TAB, SPACE, QUOTE

eg,

delimiter="TAB" encloser="QUOTE"
       
Lisa Wess's avatar
Lisa Wess
20,502 posts
18 years ago
Lisa Wess's avatar Lisa Wess

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. =)

       
Tony Silva's avatar
Tony Silva
22 posts
18 years ago
Tony Silva's avatar Tony Silva

“EE ‘cleans up’ plugin parameters, so for delimiter and encloser use the following codes rather than the actual character: TAB, SPACE, QUOTE “

I know this will sound silly, but do we use “COMMA” for the comma? That’s not a standard expression to my limited knowledge.

       
Andrew Weaver's avatar
Andrew Weaver
206 posts
18 years ago
Andrew Weaver's avatar Andrew Weaver

You should be able to just use a normal comma - the problem is mainly with ‘whitespace’ characters.

       
David Webb's avatar
David Webb
62 posts
18 years ago
David Webb's avatar David Webb

Hey Andrew, This plugin looks like it could be very useful to me on a couple of sites. Is there a way to specify categories for the “entries” to go into?

       
Tony Silva's avatar
Tony Silva
22 posts
18 years ago
Tony Silva's avatar Tony Silva

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.

       
David Webb's avatar
David Webb
62 posts
18 years ago
David Webb's avatar David Webb

Hey Tony, Just looked in the file itself and your right. It does look like we can specify a category for the entries to go into. 😊 I wonder if there’s a way to get the category from the CSV rather than specifying it. hmmm.

       
Tony Silva's avatar
Tony Silva
22 posts
18 years ago
Tony Silva's avatar Tony Silva

You’d probably have to modify the plug-in unless there’s a parameter for that…. Andrew?

       
Andrew Weaver's avatar
Andrew Weaver
206 posts
18 years ago
Andrew Weaver's avatar Andrew Weaver

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!

       
David Webb's avatar
David Webb
62 posts
18 years ago
David Webb's avatar David Webb

Cheers Andrew. I’ll test it out as soon as I’ve finalised my structure.

       
David Webb's avatar
David Webb
62 posts
18 years ago
David Webb's avatar David Webb

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.

       
David Webb's avatar
David Webb
62 posts
18 years ago
David Webb's avatar David Webb

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?

       
David Webb's avatar
David Webb
62 posts
18 years ago
David Webb's avatar David Webb

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

       
Andrew Weaver's avatar
Andrew Weaver
206 posts
18 years ago
Andrew Weaver's avatar Andrew Weaver

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?

       
1 2 3 Last

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.