how to export data from ZODB to text files

Josef Meile jmeile at hotmail.com
Wed Jun 8 12:52:44 EDT 2005


Hi Lukasz,

> Yes, I'm traing to escape from Zope-land, to be more clarify I want to
> migrate from Plone to PHP Application, which uses MySQL database
> engine, so I have to move all data from ZODB to MySQL. I suppose that
> python script shouldn`t be so complex. I need just iterate ZODB and
> write attributes like "Intro", "Body" of article to file for example.
> I need export Plone content hierarchy like
> 
> 
> Home
>    |
>    | - - - Folder 1 (Title, Intro, Body)
>    |            | - - - Article (Title, Intro, Body)
>    |   
>    | - - - Folder 2 (Title, Intro, Body)
I haven't done that with Plone, but with CMF, which is the base of
Plone. So, I guess it would be almost the same. You even don't need
the product Peter suggested; you could do a python script inside your
plone site, which searches all the objects you want and print it in
form of a pipe '|' delimited list. Then, once you define your tables
in mysql, you can import the data by copying the output of your
script and saving it into a text file. This is how my script looks like:

catalog=context.portal_catalog
jobs=catalog(
             {
               'meta_type'            : 'Internship'
             }
          )
OID = 1
for metaJob in jobs:
   jobData=catalog.getobject(metaJob.data_record_id_)
   print "%i|%s|%s|%s|%s|%s|%s|%s|" % \
     (OID,
      jobData.companyName,
      jobData.companyVision,
      jobData.description,
      jobData.positionOffered,
      jobData.jobProfile,
      jobData.contact,
      jobData.country)
   OID += 1

return printed

Off course, this only work assuming that your fields aren't files like
images or PDFs.

Regards,
Josef




More information about the Python-list mailing list