Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#13 2008-11-29 17:04:50

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

Re: jmd_csv: Batch-import articles from a CSV

jm wrote:

Download 0.2 (Requires PHP5 and 4.0.6)

The link is for version 0.1.

The current version is here: http://jmdeldin.com/txp/jmd_csv-0.2.txt

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

Offline

#14 2008-11-29 17:23:44

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

Re: jmd_csv: Batch-import articles from a CSV

It’s working well for me now, except for one issue. Thanks, Jon!

When I post the articles with jmd_csv, the values for Article Markup and Excerpt Markup are set to “Leave text untouched”, instead of “Use Textile”. I have to go through each article, choose “Use Textile” and save them. Is there a way to do this automatically?

Offline

#15 2008-12-01 04:53:07

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

Re: jmd_csv: Batch-import articles from a CSV

azw wrote:

When I post the articles with jmd_csv, the values for Article Markup and Excerpt Markup are set to “Leave text untouched”, instead of “Use Textile”. I have to go through each article, choose “Use Textile” and save them. Is there a way to do this automatically?

That should be in v0.2 (sorry about the link too). I’ll see about doing some trimming of fields and the CSV file too, so you don’t have to re-save an Excel file.

Regarding other delimiters, you could change the comma to \t for a tab. If your fields have commas in them, your editor should surround those fields with quotation marks (e.g., 'hey, man').

Also, there’s an example CSV-template in the help file too with the custom_n headers.

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

Offline

#16 2008-12-01 05:35:05

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

Re: jmd_csv: Batch-import articles from a CSV

Thanks for getting back to me, Jon!

jm wrote:

…. I’ll see about doing some trimming of fields and the CSV file too, so you don’t have to re-save an Excel file.

I think the Excel problem is fixed. I’m uploaded directly with an Excel csv now! It’s easy.

Fixing the “Leave text untouched” / “Use Textile” issue and trimming excess white space from the front and end of fields would be a great help!

You’re right that I didn’t need to worry about using a tab-delimited file. Excel’s csv conversion adds quotes around any field with a comma in it.

Last edited by azw (2008-12-01 05:36:13)

Offline

#17 2009-03-06 07:45:59

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

Re: jmd_csv: Batch-import articles from a CSV

Jon, have you thought about having this added to the plugin directory over at http://textpattern.org/plugins? It’s worth doing!

Offline

#18 2009-03-10 04:20:54

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

Re: jmd_csv: Batch-import articles from a CSV

azw wrote:

have you thought about having this added to the plugin directory over at http://textpattern.org/plugins? It’s worth doing!

I have, but I was kinda hoping something would happen with .org (slow and not really useful). I guess I’ll bite the bullet and add a slew of plugins from last summer.

Last edited by jm (2009-03-10 04:22:18)

Offline

#19 2009-10-21 18:32:44

woof
Member
Registered: 2004-08-01
Posts: 128

Re: jmd_csv: Batch-import articles from a CSV

Hi Jon-Michael

I’m trying to import a lot of articles that need different timestamps. Is there any way I can specify my own “Posted” values in the imported csv? It seems the default is to timestamp the imported articles with the current time and when I include a “Posted” column in my csv with my desired timestamp data I get the following error

Warning: Column ‘Posted’ specified twice insert into…[etc]

Is there a way around this? It would be a huge help with the task in hand, thanks

Offline

#20 2009-10-21 19:15:27

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

Re: jmd_csv: Batch-import articles from a CSV

woof wrote:

Is there a way around this? It would be a huge help with the task in hand, thanks

Try deleting this line (~L210):

Posted=now(),

Offline

#21 2009-10-21 20:41:02

woof
Member
Registered: 2004-08-01
Posts: 128

Re: jmd_csv: Batch-import articles from a CSV

jm wrote:

Try deleting this line (~L210):

Perfect — Thanks Jon-Michael!

Offline

#22 2009-11-10 14:29:28

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,532
Website GitHub Twitter

Re: jmd_csv: Batch-import articles from a CSV

Hi Jon-Michael

I used the plugin to import a bunch of article, the problem occured with line ending, even if i tryed to modify the file with notepad++ the problem still happen.

Then i decided to watch phpmyadmin to see what is trored in db, then i found that body_html column of textpattern table is the same a body column, in a regular article the body_html is the html version of the body, and watching at the code i see that you dont insert html version, you only copy the body column to body_html column.

Hope that help.

Offline

#23 2009-11-10 15:46:32

Dragondz
Moderator
From: Algérie
Registered: 2005-06-12
Posts: 1,532
Website GitHub Twitter

Re: jmd_csv: Batch-import articles from a CSV

Hi Jon, me again,

I think it s not a bug because you set textile_body=0 and textile_excerpt=0 to import like a text.

I need to import the articles like html, then i make a modification to your plugin to do that and here is it:

public function import($handle, $status)
    {
        global $prefs, $txp_user;
        include txpath.'/lib/classTextile.php';
        $htm = new Textile;
        $row = 1;
        while (($csv = fgetcsv($handle, 0, ',')) !== FALSE)
        {
            $fields = count($csv);
            if ($row === 1)
            {
                for ($i = 0; $i < $fields; $i++)
                {
                    $header[$i] = $csv[$i];
                }
            }
            else
            {
                $insert = '';
                foreach ($header as $key => $value)
                {
                    // escape all fields
                    // $csv[$key] = doSlash($csv[$key]);
                    if ($value === 'Title')
                    {
                        $url_title = stripSpace($csv[$key], 1);
                    }
                    if ($value === 'Body' || $value === 'Excerpt')
                    {
                        $insert .= "{$value}_html='{$htm->TextileThis($csv[$key])}',";
                    }
                    $csv[$key] = doSlash($csv[$key]);
                    $insert .= "{$value}='{$csv[$key]}',";
                }
                $uid = md5(uniqid(rand(),true));
                $insert .= <<<EOD
AuthorID='{$txp_user}',
LastModID='{$txp_user}',
AnnotateInvite='{$prefs['comments_default_invite']}',
url_title='{$url_title}',
uid='{$uid}',
feed_time=now(),
Posted=now(),
LastMod=now(),
Status={$status},
textile_body=1,
textile_excerpt=1
EOD;
                safe_insert('textpattern', $insert);
            }
            $row++;
        }
    }

Hope that help.

Offline

#24 2009-11-21 02:11:25

karl.dvx
Member
Registered: 2007-11-20
Posts: 33
Website

Re: jmd_csv: Batch-import articles from a CSV

Aargh, been trying to make this plugin work for over two hours now, but I can’t seem to get it working..

This is what I’m doing:
1. Installed and activated the plugin
2. Made the “jmd_csv” category under the files
3. Upload a .csv file, give it “jmd_csv” category.
4. Import the .csv file in the Extensions tab
5. I get the “CSV imported successfully” message

But now, when I go to my articles I can’t see any of the imported articles…

In my .csv file I have a Title, Body, Excerpt and Section.
The articles in the Section row is the real name of a section on my site.

This is how my .csv file looks.

Can somebody please tell me what I’m doing wrong?
This plugin could save me 10 hours a month..
THANKS!

Offline

Board footer

Powered by FluxBB