[Zope-CMF] Importing TSV to Members

Tres Seaver tseaver@zope.com
26 Apr 2002 18:32:54 -0400

On Fri, 2002-04-26 at 14:19, Dameron Midgette wrote:
> Hi All!
>     I'm needing to create a bunch of new mwmbers in an empty CMF site,
> from a tab-separated text file (access export). I've got the new fields
> set up in portal_memberdata, and i'm working on changing the join and
> personalize fields for later additions, but I have one big batch to add
> from this file.
>     Parsing the file shouldn't be *too* hard (I'm a python newbie); if
> anyone wants to spell it out, that would be fine, though :) The thing I
> really need help with is the syntax for creating a new member, complete
> with member folder and lots of extra metadata, etc.. (Having emails sent
> with passwords to each member as they are imported would be a great bonus!)
>     Any and all suggestions, snippets, and solutions welcome! TIA

An external method should do the trick, something like::

from CMFCore.utilities import getToolByName

def bulkLoadMembers( self ):
        Create members from a "tab-separated values" text file, where
        the tab-delimited values are:

        - userid
        - full name
        - email address
        - favorite color (modify ad lib.)
    rt = getToolByName( 'self', 'portal_registration' )

    for line in open( 'somefile.tsv' ).readlines():

        # Doctor this to represent your actual properties
        userid, name, email, favorite_color = line.split( '\t' )

        password = rt.generatePassword()

        rt.addMember( userid, password
                    , properties={ 'name' : name
                                 , 'email' : email
                                 , 'favorite_color' : favorite_color
                                 } )

        rt.registeredNotify( userid ) # send welcome mail w/ password

Tres Seaver                                tseaver@zope.com
Zope Corporation      "Zope Dealers"       http://www.zope.com