Converting txt files to nodes - IS IT POSS???

JackThompson - June 16, 2009 - 14:39

Is it possible (as-is) to convert txt files to nodes?

I have 40,000 txt files that I want to convert to nodes.
Any ideaS?

We need way more info.

spatz4000 - June 16, 2009 - 15:06

We need way more info.

Yes

pcs305 - June 16, 2009 - 15:31

It is possible.
You can look at the Import/Export (http://drupal.org/project/importexportapi) module,or some of the other Import modules, to see if they will do what you want.

You can also write a script too batch import massive amounts of txt files into nodes. This way will give you the most flexibility.
I used this method to import MSWord documents into nodes.

Thanks for the advice!

JackThompson - June 16, 2009 - 17:18

Thanks for the advice!

Is there a limit as to how

JackThompson - June 17, 2009 - 03:15

Is there a limit as to how many nodes i can have? I need 50,000 +

No limit! 50,000 should not

pcs305 - June 17, 2009 - 17:31

No limit!
50,000 should not be a problem at all.

Did you find an example of the batch scripts?

Not really. I dont think

JackThompson - June 17, 2009 - 18:13

Not really. I dont think there is anything out there that will do what I need.

Which is..

To take certain bits of data from each of my txt files and create content types with that data and a node as a whole.

Do you know of anything for Drupal 6?

No

pcs305 - June 17, 2009 - 20:02

Mine was MSWord Documents that was templates completed by users.
So the paragraph headers was the same across all the documents.

I dumped them to TXT file format, wrote a perl script to extract the data I needed from the TXT file
and the script writes out a Drupal PHP file that can be executed to build the Drupal nodes.

I'm not a programmer but if you need examples let me know.

Thats awesome bro. Can you

JackThompson - June 18, 2009 - 16:44

Thats awesome bro. Can you tell me more about the Drupal PHP file? How do you use a php file to build nodes?

PHP

pcs305 - June 18, 2009 - 21:10

Here is my example:

<?php
// Bootstrap Drupal
require 'includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
?>

<?php
// Construct the new node object.
$node = new stdClass();

// Data from docpars.
$node->field_x_implementation[0]['value'] = 'Neque iustum te saepius similis vulpes augue odio esca ';
$node->field_vendor_purpose[0]['value'] = 'Typicus sit odio vero quadrum abluo. Uxor vulpes jus roto refero abluo praemitto.';
$node->field_x_interaction[0]['value'] = 'Legibus';
$node->field_x_comments[0]['value'] = 'Illum quidem decet aptent vereor. Usitas verto in facilisis os populus.';
$node->field_x_verification[0]['value'] = 'Vindico abluo commoveo iustum nunc aptent tation lenis minim.';
$node->field_src_language[0]['value'] = 'ASM        ';
$node->field_x_specific_sec[0]['value'] = 'None';
$node->field_x_general_sec[0]['value'] = 'Occuro cui nibh pagus jus adipiscing iaceo macto quia. Dignissim elit patria.';
$node->field_x_contacts[0]['value'] = 'Premo eros meus ludus iriure validus exputo elit suscipere ex.';
$node->field_x_logic[0]['value'] = 'Melior neo decet causa veniam nulla pneum dolor probo quia.';
$node->field_x_regions_activated[0]['value'] = 'saepius haero paulatim rusticus.';
$node->field_usage[0]['value'] = 'INTERNAL';
$node->field_orig_author[0]['value'] = 'George Orwell';
$node->field_ref_manual[0]['value'] = 'DRUPAL Books';
$node->field_src_location[0]['value'] = 'library';

$node->title = 'THIS IS the NODE TITLE';
$node->type = 'exits';  
$node->created = time();
$node->changed = $node->created;
$node->status = 1;
$node->promote = 1;
$node->sticky = 0;
$node->format = 1;       // Filtered HTML
$node->uid = 1;          // UID of content owner
$node->language = 'en';
node_save($node);
?>

This is to create a CCK node of type "exits' I created. All the $node->field_xx_xxx[0]['value'] = stuff is CCK fields.
The $node->... stuff is needed for the Drupal node creation.

You just point the browser to the php file and it will execute the script.

If you're got 40000 files,

mtsanford - June 18, 2009 - 21:30

If you're got 40000 files, careful of timeouts. You may want to run from a command prompt, break up in to smaller batches etc.

You'll have to write your own php script, and php forums are probably best for help on that. The script given above is a good starting point. Build a node object, then call node_save for each node and drupal does the rest.

Awesome. Thanks a lot for

JackThompson - June 19, 2009 - 13:58

Awesome. Thanks a lot for taking the time to help out.
This is a great step in the right direction.

 
 

Drupal is a registered trademark of Dries Buytaert.