|
|
Choosing A Webhost: |
Re: Importing contacts from delimited files: msg#00002cms.opengroupware.xmlrpc.devel
On Fri, 2007-04-13 at 13:30 -0400, Adam Tauno Williams wrote: > > Adam from the users@ mailing list recommended I hop on over here for a few > > questions/help with XML-RPC scripts. > > I was told its possible and actually VERY easy to import a number of > > contacts > > from a delimited file using Python/XML-RPC scripts. I was wondering if > > someone > > could provide some help as to how this is actually done. > Here is one simple example - > #!/usr/bin/env python > > import sys, csv, xmlrpclib, pprint > server = xmlrpclib.Server('http://{USER}:{PASSWORD}@{HOST}/RPC2') > reader = csv.reader(open("{FILENAME}", "rb"), delimiter='|', > quoting=csv.QUOTE_NONE) Here is a more complicated example that creates both contacts and enterprises, breaking enterprises by changes in the ZIP+4, and it sets the permissions on all created objects to specific teams - #!/usr/bin/env python import sys, csv, xmlrpclib, pprint server = xmlrpclib.Server('http://adam:********@gourd-amber/RPC2') reader = csv.reader(open("MECustomerListforOGoLoad.aaaf.csv", "rb"), delimiter='|', quoting=csv.QUOTE_NONE) previousZIP = '' for row in reader: currentZIP = row[5] if currentZIP != previousZIP or len(currentZIP) == 5: print "%s: ZIP code changed" %row[0] result = {} if len(row[14]) > 0: fSpec = {} fSpec['qualifier'] = "bankCode = '%s' " % row[14] result = server.enterprise.fetch(fSpec) if len(result) == 0: print "Creating new enterprise" enterprise = {} enterprise['name'] = row[1] enterprise['bankCode'] = row[14] enterprise['url'] = row[9] enterprise['addresses'] = {} enterprise['addresses']['ship'] = {} enterprise['addresses']['ship']['name1'] = row[1] enterprise['addresses']['ship']['street'] = row[2] enterprise['addresses']['ship']['city'] = row[3] enterprise['addresses']['ship']['state'] = row[4] enterprise['addresses']['ship']['zip'] = row[5] enterprise['addresses']['ship']['country'] = 'USA' enterprise['addresses']['ship']['type'] = 'ship' enterprise['extendedKeys'] = ['salesperson', 'division', 'mailmktcode'] enterprise['extendedAttrs'] = {} enterprise['extendedAttrs']['salesperson'] = row[16] enterprise['extendedAttrs']['division'] = row[17] enterprise['extendedAttrs']['mailmktcode'] = row[15] enterprise['phones'] = {} enterprise['phones']['01_tel'] = {} enterprise['phones']['01_tel']['number'] = row[7] enterprise['phones']['01_tel']['info'] = '' enterprise['phones']['01_tel']['type'] = '01_tel' enterprise['phones']['10_fax'] = {} enterprise['phones']['10_fax']['number'] = row[8] enterprise['phones']['10_fax']['info'] = '' enterprise['phones']['10_fax']['type'] = '10_fax' enterpriseId = server.enterprise.insert(enterprise) print "Enterprise Id %s created " % enterpriseId server.access.setOperationOnObjectForAccess('rw', enterpriseId, 955240); server.access.setOperationOnObjectForAccess('rw', enterpriseId, 11530); print " Permission applied to enterprise." else: print "Enterprise with bankCode already exists" enterpriseId = result[0]['id'].split('/')[4] print "Enterprise Id %s " % enterpriseId else: print "%s: ZIP code unchanged" %row[0] previousZIP = currentZIP if len(row[10]) > 0: contact = {} contact['firstname'] = row[11] contact['name'] = row[12] contact['nickname'] = row[10] contact['isPrivate'] = '0' contact['extendedKeys'] = ['organization', 'job_title', 'mailmktcode', 'salesperson', 'division'] contact['extendedAttrs'] = {} contact['extendedAttrs']['organization'] = row[1] contact['extendedAttrs']['job_title'] = row[13] contact['extendedAttrs']['mailmktcode'] = row[15] contact['extendedAttrs']['salesperson'] = row[16] contact['extendedAttrs']['division'] = row[17] contact['phones'] = {} contact['phones']['01_tel'] = {} contact['phones']['01_tel']['number'] = row[7] contact['phones']['01_tel']['info'] = '' contact['phones']['01_tel']['type'] = '01_tel' contact['phones']['10_fax'] = {} contact['phones']['10_fax']['number'] = row[8] contact['phones']['10_fax']['info'] = '' contact['phones']['10_fax']['type'] = '10_fax' contact['addresses'] = {} contact['addresses']['mailing'] = {} contact['addresses']['mailing']['name1'] = row[1] contact['addresses']['mailing']['name2'] = row[10] contact['addresses']['mailing']['street'] = row[2] contact['addresses']['mailing']['city'] = row[3] contact['addresses']['mailing']['state'] = row[4] contact['addresses']['mailing']['zip'] = row[5] contact['addresses']['mailing']['country'] = 'USA' contact['addresses']['mailing']['type'] = 'mailing' contactId = server.person.insert(contact) print " Contact Id %s created " % contactId server.enterprise.insertPerson(enterpriseId, contactId); print " Contact Id %s added to Enterprise Id %s " % (contactId, enterpriseId) server.access.setOperationOnObjectForAccess('rw', contactId, 955240); server.access.setOperationOnObjectForAccess('rw', contactId, 11530); print " Permissions applied to contact."
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: Importing contacts from delimited files, Adam Tauno Williams |
|---|---|
| Next by Date: | Re: Importing contacts from delimited files, chris h |
| Previous by Thread: | Re: Importing contacts from delimited files, Adam Tauno Williams |
| Next by Thread: | Re: Importing contacts from delimited files, chris h |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
Free MagazinesCisco NewsReceive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business. subscribe Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field. subscribe The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business. subscribe Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company. subscribe Total Telecom Total Telecom is "The Economist of the communications industry". subscribe |
Home
| advertise | OSDir is
an inevitable website.
|