Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#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,559
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,559
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

#25 2009-11-22 07:46:20

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

Re: jmd_csv: Batch-import articles from a CSV

Hi Karl

In the image there is title, body,excerpt, section;

I use Title, Excerpt,.. The first letter must be uppercase (i think), try if it works!

Cheers

Offline

#26 2009-12-14 14:43:43

HAC
Member
From: Vietnam
Registered: 2009-06-05
Posts: 33
Website

Re: jmd_csv: Batch-import articles from a CSV

works like a charm! thank you very much for your great import script!

Offline

#27 2009-12-16 09:41:45

HAC
Member
From: Vietnam
Registered: 2009-06-05
Posts: 33
Website

Re: jmd_csv: Batch-import articles from a CSV

i have a question. what will happen if there are two or more duplicated articles in .csv?

Offline

#28 2009-12-16 09:53:41

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: jmd_csv: Batch-import articles from a CSV

HAC wrote:

i have a question. what will happen if there are two or more duplicated articles in .csv?

As in dublicated content? Then there will be multiple articles with same content.

Offline

#29 2009-12-16 10:08:07

HAC
Member
From: Vietnam
Registered: 2009-06-05
Posts: 33
Website

Re: jmd_csv: Batch-import articles from a CSV

When we add new article manually in txp! we will get this message Article posted. The same URL-only title is used by 2 different articles. when we try to add another article with the same URL-only title

so i wonder if there is a way to prevent duplicated articles with URL-only title?!

Offline

#30 2009-12-16 10:17:30

HAC
Member
From: Vietnam
Registered: 2009-06-05
Posts: 33
Website

Re: jmd_csv: Batch-import articles from a CSV

function check_url_title($url_title)
	{
		// Check for blank or previously used identical url-titles
		if (strlen($url_title) === 0)
		{
			return gTxt('url_title_is_blank');
		}
		else
		{
			$url_title_count = safe_count('textpattern', "url_title = '$url_title'");
			if ($url_title_count > 1)
			{
				return gTxt('url_title_is_multiple', array('{count}' => $url_title_count));
			}
		}
		return '';
	}

finally, i found the one i need in txp_article.php
i’ll try to modify the script to fit my need! _

Last edited by HAC (2009-12-16 10:19:57)

Offline

Board footer

Powered by FluxBB